本文介绍了Google地图 - 获取区域/邻域的多边形边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Google Maps API v3上进行一次简单的搜索,然后获得带有彩色多边形的地图,如下图所示:



搜索:pinheiros,圣保罗



解决方案

我通过使用


  • 点击右边的邻居按钮,然后选择编辑多元
    将JSON转换为WKT。我不复制整个JSON仅Regex中的points数组中的对象。在RegExr上,我复制替换的文本并粘贴到 POLYGON((pastehere))中。



    重要!应用正则表达式后,您需要重复上一点的第一个点。



    'BLOCKQUOTE>

    -61.956523060798645 -10.877613428213532 下, - 61.95640504360199 -10.877718788854143,-61.956791281700134 -10.878393096072424,-61.95735991001129 -10.87805594265392,-61.95682346820831 -10.877339490373695,的 -61.956523060798645 -10.877613428213532


    然后你得到这样的东西:

      POLYGON(( -  61.956523060798645 -10.877613428213532,-61.95640504360199 -10.877718788854143,-61.956791281700134 -10.878393096072424,-61.95735991001129 -10.87805594265392,-61.95682346820831 -10.877339490373695,-61.956523060798645 -10.877613428213532))

    可以插入支持WKT的数据库(如MySQL)。



    WikiMapia有一个,那么所有这些过程都可以是au tomatic,但这对我来说很好。


    I want to make a simple search on Google Maps API v3 and get as a result the map with a colored polygon like the picture below:

    Search: pinheiros, sao paulo

    解决方案

    I got it by using WikiMapia data.

    The steps are:

    • Search the location that you want.
    • Click with the right button on neighborhood and choose Edit Poly.
    • On the developer tools click in Network and filter by getPolygon.
    • Copy server response that looks like:

    • And go to Console tab to execute the function: Wikimapia.Parser.Itiles.prototype.decodePolygon("Copyed text here");

    • Press enter to execute after this the Console will return the object with the points (The path of Poly).

    I use JSON.stringify to transform the object in JSON.

    Example:

    JSON.stringify(Wikimapia.Parser.Itiles.prototype.decodePolygon("-619402099;-109032887;02fe8953fffe5a000ae5fe379a000fedffd250000e40ffd6050007f7ffeff2001925ffd59b001f6fffdc310012dcffed10003b82ffd9b9005514ffc4520053d2ffc807000c92fff82dfffde7000e670005070012ef0009390021bf000572001358fffc3a001a57fffa210013c1ffff940036530008610022fc000284004732fff5f0001fb1fff2960013c1fff80800594efffde7002c72000f16004b5000204600416f0013b2002292"))
    

    The code above will return this JSON (indentation in JsonFormatter):

    {
       "points":[
          {
             "lat":-10.9032887,
             "lng":-61.9402099
          },
          {
             "lat":-10.9032466,
             "lng":-61.9306183
          },
          {
             "lat":-10.8915629,
             "lng":-61.9308972
          },
          {
             "lat":-10.8903934,
             "lng":-61.9313049
          },
          {
             "lat":-10.8893188,
             "lng":-61.9316697
          },
          {
             "lat":-10.8889079,
             "lng":-61.9318736
          },
          {
             "lat":-10.8878227,
             "lng":-61.9325173
          },
          {
             "lat":-10.8869061,
             "lng":-61.933322
          },
          {
             "lat":-10.8864214,
             "lng":-61.9338048
          },
          {
             "lat":-10.8854416,
             "lng":-61.9353282
          },
          {
             "lat":-10.8839139,
             "lng":-61.9375062
          },
          {
             "lat":-10.8824811,
             "lng":-61.939652
          },
          {
             "lat":-10.8822809,
             "lng":-61.9399738
          },
          {
             "lat":-10.8826496,
             "lng":-61.9399202
          },
          {
             "lat":-10.8831343,
             "lng":-61.9400489
          },
          {
             "lat":-10.8839982,
             "lng":-61.940285
          },
          {
             "lat":-10.8844934,
             "lng":-61.9404244
          },
          {
             "lat":-10.8851677,
             "lng":-61.9403279
          },
          {
             "lat":-10.8856734,
             "lng":-61.9401777
          },
          {
             "lat":-10.8870641,
             "lng":-61.940167
          },
          {
             "lat":-10.8879597,
             "lng":-61.9403815
          },
          {
             "lat":-10.8897823,
             "lng":-61.9404459
          },
          {
             "lat":-10.8905936,
             "lng":-61.9401884
          },
          {
             "lat":-10.8910993,
             "lng":-61.9398451
          },
          {
             "lat":-10.8933855,
             "lng":-61.9396412
          },
          {
             "lat":-10.8945233,
             "lng":-61.9395876
          },
          {
             "lat":-10.8964513,
             "lng":-61.9399738
          },
          {
             "lat":-10.8981264,
             "lng":-61.9408
          },
          {
             "lat":-10.8990114,
             "lng":-61.9413042
          }
       ],
       "bounds":{
          "left":-61.9413042,
          "bottom":-10.9032887,
          "right":-61.9306183,
          "top":-10.8822809,
          "centerLatLng":null
       }
    }
    

    Finally I use regex like this regexr.com/3c5m2 to turn JSON into WKT. I don't copy entire JSON only the objects in "points" array in Regex. On RegExr I copy the replaced text and paste in POLYGON((pastehere)).

    Important! After apply the regex you need to repeat the first point in last point.

    Then you get something like this:

    POLYGON((-61.956523060798645 -10.877613428213532,-61.95640504360199 -10.877718788854143,-61.956791281700134 -10.878393096072424,-61.95735991001129 -10.87805594265392,-61.95682346820831 -10.877339490373695,-61.956523060798645 -10.877613428213532))
    

    That can be inserted in database that supports WKT (like MySQL).

    WikiMapia has an API then all of this process can be automatic, but this works fine for me.

    这篇关于Google地图 - 获取区域/邻域的多边形边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:38