zoukankan      html  css  js  c++  java
  • 通过经纬度获取地理位置详细信息

    1、访问接口 http://maps.google.cn/maps/api/geocode/json?latlng=31.213751,121.390694&language=CN

      latlng对应的值:Latitude,Longitude

      language可选值:EN是英文,CN是中文

      返回json数据如下:

      

      1 {
      2    "results" : [
      3       {
      4          "address_components" : [
      5             {
      6                "long_name" : "天山路461弄3号",
      7                "short_name" : "天山路461弄3号",
      8                "types" : [ "premise" ]
      9             },
     10             {
     11                "long_name" : "天山",
     12                "short_name" : "天山",
     13                "types" : [ "neighborhood", "political" ]
     14             },
     15             {
     16                "long_name" : "长宁区",
     17                "short_name" : "长宁区",
     18                "types" : [ "sublocality_level_1", "sublocality", "political" ]
     19             },
     20             {
     21                "long_name" : "上海市",
     22                "short_name" : "上海市",
     23                "types" : [ "locality", "political" ]
     24             },
     25             {
     26                "long_name" : "上海市",
     27                "short_name" : "上海市",
     28                "types" : [ "administrative_area_level_1", "political" ]
     29             },
     30             {
     31                "long_name" : "中国",
     32                "short_name" : "CN",
     33                "types" : [ "country", "political" ]
     34             }
     35          ],
     36          "formatted_address" : "中国上海市长宁区天山天山路461弄3号",
     37          "geometry" : {
     38             "bounds" : {
     39                "northeast" : {
     40                   "lat" : 31.2137575,
     41                   "lng" : 121.3910541
     42                },
     43                "southwest" : {
     44                   "lat" : 31.2135446,
     45                   "lng" : 121.3906149
     46                }
     47             },
     48             "location" : {
     49                "lat" : 31.2136459,
     50                "lng" : 121.3908117
     51             },
     52             "location_type" : "ROOFTOP",
     53             "viewport" : {
     54                "northeast" : {
     55                   "lat" : 31.2150000302915,
     56                   "lng" : 121.3921834802915
     57                },
     58                "southwest" : {
     59                   "lat" : 31.2123020697085,
     60                   "lng" : 121.3894855197085
     61                }
     62             }
     63          },
     64          "place_id" : "ChIJj4ESeZhlsjURTE12jwPHLZ4",
     65          "types" : [ "premise" ]
     66       },
     67       {
     68          "address_components" : [
     69             {
     70                "long_name" : "461",
     71                "short_name" : "461",
     72                "types" : [ "street_number" ]
     73             },
     74             {
     75                "long_name" : "天山路",
     76                "short_name" : "天山路",
     77                "types" : [ "route" ]
     78             },
     79             {
     80                "long_name" : "天山",
     81                "short_name" : "天山",
     82                "types" : [ "neighborhood", "political" ]
     83             },
     84             {
     85                "long_name" : "长宁区",
     86                "short_name" : "长宁区",
     87                "types" : [ "sublocality_level_1", "sublocality", "political" ]
     88             },
     89             {
     90                "long_name" : "上海市",
     91                "short_name" : "上海市",
     92                "types" : [ "locality", "political" ]
     93             },
     94             {
     95                "long_name" : "上海市",
     96                "short_name" : "上海市",
     97                "types" : [ "administrative_area_level_1", "political" ]
     98             },
     99             {
    100                "long_name" : "中国",
    101                "short_name" : "CN",
    102                "types" : [ "country", "political" ]
    103             }
    104          ],
    105          "formatted_address" : "中国上海市长宁区天山天山路461号",
    106          "geometry" : {
    107             "location" : {
    108                "lat" : 31.213864,
    109                "lng" : 121.390561
    110             },
    111             "location_type" : "ROOFTOP",
    112             "viewport" : {
    113                "northeast" : {
    114                   "lat" : 31.2152129802915,
    115                   "lng" : 121.3919099802915
    116                },
    117                "southwest" : {
    118                   "lat" : 31.2125150197085,
    119                   "lng" : 121.3892120197085
    120                }
    121             }
    122          },
    123          "place_id" : "ChIJTd66cJhlsjURR4BQl8lDmE4",
    124          "types" : [ "street_address" ]
    125       },
    126       {
    127          "address_components" : [
    128             {
    129                "long_name" : "天山",
    130                "short_name" : "天山",
    131                "types" : [ "neighborhood", "political" ]
    132             },
    133             {
    134                "long_name" : "长宁区",
    135                "short_name" : "长宁区",
    136                "types" : [ "sublocality_level_1", "sublocality", "political" ]
    137             },
    138             {
    139                "long_name" : "上海市",
    140                "short_name" : "上海市",
    141                "types" : [ "locality", "political" ]
    142             },
    143             {
    144                "long_name" : "上海市",
    145                "short_name" : "上海市",
    146                "types" : [ "administrative_area_level_1", "political" ]
    147             },
    148             {
    149                "long_name" : "中国",
    150                "short_name" : "CN",
    151                "types" : [ "country", "political" ]
    152             }
    153          ],
    154          "formatted_address" : "中国上海市长宁区天山",
    155          "geometry" : {
    156             "bounds" : {
    157                "northeast" : {
    158                   "lat" : 31.2202375,
    159                   "lng" : 121.4134483
    160                },
    161                "southwest" : {
    162                   "lat" : 31.2033601,
    163                   "lng" : 121.3754702
    164                }
    165             },
    166             "location" : {
    167                "lat" : 31.210196,
    168                "lng" : 121.403524
    169             },
    170             "location_type" : "APPROXIMATE",
    171             "viewport" : {
    172                "northeast" : {
    173                   "lat" : 31.2202375,
    174                   "lng" : 121.4134483
    175                },
    176                "southwest" : {
    177                   "lat" : 31.2033601,
    178                   "lng" : 121.3754702
    179                }
    180             }
    181          },
    182          "place_id" : "ChIJszng-aFlsjURvtNMjIbvdao",
    183          "types" : [ "neighborhood", "political" ]
    184       },
    185       {
    186          "address_components" : [
    187             {
    188                "long_name" : "长宁区",
    189                "short_name" : "长宁区",
    190                "types" : [ "sublocality_level_1", "sublocality", "political" ]
    191             },
    192             {
    193                "long_name" : "上海市",
    194                "short_name" : "上海市",
    195                "types" : [ "locality", "political" ]
    196             },
    197             {
    198                "long_name" : "上海市",
    199                "short_name" : "上海市",
    200                "types" : [ "administrative_area_level_1", "political" ]
    201             },
    202             {
    203                "long_name" : "中国",
    204                "short_name" : "CN",
    205                "types" : [ "country", "political" ]
    206             }
    207          ],
    208          "formatted_address" : "中国上海市长宁区",
    209          "geometry" : {
    210             "bounds" : {
    211                "northeast" : {
    212                   "lat" : 31.2439818,
    213                   "lng" : 121.4394642
    214                },
    215                "southwest" : {
    216                   "lat" : 31.1777819,
    217                   "lng" : 121.3318037
    218                }
    219             },
    220             "location" : {
    221                "lat" : 31.220367,
    222                "lng" : 121.424624
    223             },
    224             "location_type" : "APPROXIMATE",
    225             "viewport" : {
    226                "northeast" : {
    227                   "lat" : 31.2439818,
    228                   "lng" : 121.4394642
    229                },
    230                "southwest" : {
    231                   "lat" : 31.1777819,
    232                   "lng" : 121.3318037
    233                }
    234             }
    235          },
    236          "place_id" : "ChIJv23gDLllsjURsoq50CLhTOU",
    237          "types" : [ "sublocality_level_1", "sublocality", "political" ]
    238       },
    239       {
    240          "address_components" : [
    241             {
    242                "long_name" : "上海市",
    243                "short_name" : "上海市",
    244                "types" : [ "locality", "political" ]
    245             },
    246             {
    247                "long_name" : "上海市",
    248                "short_name" : "上海市",
    249                "types" : [ "administrative_area_level_1", "political" ]
    250             },
    251             {
    252                "long_name" : "中国",
    253                "short_name" : "CN",
    254                "types" : [ "country", "political" ]
    255             }
    256          ],
    257          "formatted_address" : "中国上海市上海市",
    258          "geometry" : {
    259             "bounds" : {
    260                "northeast" : {
    261                   "lat" : 31.8682169,
    262                   "lng" : 122.2470663
    263                },
    264                "southwest" : {
    265                   "lat" : 30.68027,
    266                   "lng" : 120.8582175
    267                }
    268             },
    269             "location" : {
    270                "lat" : 31.230416,
    271                "lng" : 121.473701
    272             },
    273             "location_type" : "APPROXIMATE",
    274             "viewport" : {
    275                "northeast" : {
    276                   "lat" : 31.6688967,
    277                   "lng" : 122.1137989
    278                },
    279                "southwest" : {
    280                   "lat" : 30.7798012,
    281                   "lng" : 120.8397067
    282                }
    283             }
    284          },
    285          "place_id" : "ChIJMzz1sUBwsjURoWTDI5QSlQI",
    286          "types" : [ "locality", "political" ]
    287       },
    288       {
    289          "address_components" : [
    290             {
    291                "long_name" : "上海市",
    292                "short_name" : "上海市",
    293                "types" : [ "administrative_area_level_1", "political" ]
    294             },
    295             {
    296                "long_name" : "中国",
    297                "short_name" : "CN",
    298                "types" : [ "country", "political" ]
    299             }
    300          ],
    301          "formatted_address" : "中国上海市",
    302          "geometry" : {
    303             "bounds" : {
    304                "northeast" : {
    305                   "lat" : 31.8682169,
    306                   "lng" : 122.2470663
    307                },
    308                "southwest" : {
    309                   "lat" : 30.68027,
    310                   "lng" : 120.8582175
    311                }
    312             },
    313             "location" : {
    314                "lat" : 31.230416,
    315                "lng" : 121.473701
    316             },
    317             "location_type" : "APPROXIMATE",
    318             "viewport" : {
    319                "northeast" : {
    320                   "lat" : 31.8682169,
    321                   "lng" : 122.0114717
    322                },
    323                "southwest" : {
    324                   "lat" : 30.68027,
    325                   "lng" : 120.8582175
    326                }
    327             }
    328          },
    329          "place_id" : "ChIJBftfxTICsjUR_z-KXanY9fI",
    330          "types" : [ "administrative_area_level_1", "political" ]
    331       },
    332       {
    333          "address_components" : [
    334             {
    335                "long_name" : "中国",
    336                "short_name" : "CN",
    337                "types" : [ "country", "political" ]
    338             }
    339          ],
    340          "formatted_address" : "中国",
    341          "geometry" : {
    342             "bounds" : {
    343                "northeast" : {
    344                   "lat" : 53.56097399999999,
    345                   "lng" : 134.7728099
    346                },
    347                "southwest" : {
    348                   "lat" : 18.1576156,
    349                   "lng" : 73.4994136
    350                }
    351             },
    352             "location" : {
    353                "lat" : 35.86166,
    354                "lng" : 104.195397
    355             },
    356             "location_type" : "APPROXIMATE",
    357             "viewport" : {
    358                "northeast" : {
    359                   "lat" : 53.56097399999999,
    360                   "lng" : 134.7728099
    361                },
    362                "southwest" : {
    363                   "lat" : 18.1576156,
    364                   "lng" : 73.4994136
    365                }
    366             }
    367          },
    368          "place_id" : "ChIJwULG5WSOUDERbzafNHyqHZU",
    369          "types" : [ "country", "political" ]
    370       }
    371    ],
    372    "status" : "OK"
    373 }
    View Code


    2、解析就可以得到详细地理位置信息了。

    备注:微信获取的经纬度是google的。

      

     1 <xml>
     2 <ToUserName><![CDATA[gh_f4dbc9a2]]></ToUserName>
     3 <FromUserName><![CDATA[orWHF]]></FromUserName>
     4 <CreateTime>1458724244</CreateTime>
     5 <MsgType><![CDATA[event]]></MsgType>
     6 <Event><![CDATA[LOCATION]]></Event>
     7 <Latitude>31.213751</Latitude>
     8 <Longitude>121.390694</Longitude>
     9 <Precision>40.000000</Precision>
    10 </xml>
    View Code

      Precision是精确度

  • 相关阅读:
    20.12.2 leetcode7
    20.12.1 leetcode34
    20.11.30 leetcode767
    20.11.29 leetcode976
    Codeforces632E 选择/小偷与商店 背包DP
    魔法少女 DP NG放的水
    逆反的01串 模拟 NG放的水
    最大数maxnumber bzoj1012 JSOI2008 单调队列
    组合数问题 vijos2006 NOIP2016 D2T1 杨辉三角 排列组合 前缀和
    信息传递 vijos1979 NOIP2015D1T2 强连通分量 tarjan模版题
  • 原文地址:https://www.cnblogs.com/itslives-com/p/Location.html
Copyright © 2011-2022 走看看