【问题标题】:GoogleMaps API is giving out manchester address instead of Piccadilly Circus, London, UKGoogle Maps API 提供曼彻斯特地址而不是英国伦敦皮卡迪利广场
【发布时间】:2016-11-21 21:30:09
【问题描述】:

以下 http 请求给出的是曼彻斯特的位置,而不是伦敦的实际皮卡迪利广场地址:

https://maps.googleapis.com/maps/api/geocode/json?address=Piccadilly英国伦敦马戏团

不过,当我在 GoogleMaps 中搜索“英国伦敦皮卡迪利广场”时,我会在地图上找到正确的位置。

以下是从 API 调用获得的结果 JSON:

{
  "results": [
    {
      "address_components": [
        {
          "long_name": "Piccadilly",
          "short_name": "Piccadilly",
          "types": [
            "establishment",
            "point_of_interest"
          ]
        },
        {
          "long_name": "London Rd",
          "short_name": "London Rd",
          "types": [
            "route"
          ]
        },
        {
          "long_name": "Manchester",
          "short_name": "Manchester",
          "types": [
            "locality",
            "political"
          ]
        },
        {
          "long_name": "Manchester",
          "short_name": "Manchester",
          "types": [
            "postal_town"
          ]
        },
        {
          "long_name": "Greater Manchester",
          "short_name": "Greater Manchester",
          "types": [
            "administrative_area_level_2",
            "political"
          ]
        },
        {
          "long_name": "England",
          "short_name": "England",
          "types": [
            "administrative_area_level_1",
            "political"
          ]
        },
        {
          "long_name": "",
          "short_name": "GB",
          "types": [
            "country",
            "political"
          ]
        },
        {
          "long_name": "M60",
          "short_name": "M60",
          "types": [
            "postal_code"
          ]
        }
      ],
      "formatted_address": "Piccadilly, London Rd, Manchester M60",
      "geometry": {
        "location": {
          "lat": 53.4771243,
          "lng": -2.2310505
        },
        "location_type": "APPROXIMATE",
        "viewport": {
          "northeast": {
            "lat": 53.4784732802915,
            "lng": -2.229701519708498
          },
          "southwest": {
            "lat": 53.4757753197085,
            "lng": -2.232399480291502
          }
        }
      },
      "partial_match": true,
      "place_id": "ChIJ9flXEJaxe0gRpCvy-ySgeBs",
      "types": [
        "establishment",
        "light_rail_station",
        "point_of_interest",
        "transit_station"
      ]
    }
  ],
  "status": "OK"
}

【问题讨论】:

标签: json google-maps


【解决方案1】:

我认为问题出在搜索键上,其实是下面的请求

https://maps.googleapis.com/maps/api/geocode/json?address=Piccadilly%20Circus%20Station,%20London,%20UK

得到正确答案

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Piccadilly Circus Station",
               "short_name" : "Piccadilly Circus Station",
               "types" : [ "establishment", "point_of_interest" ]
            },
            {
               "long_name" : "Piccadilly Circus",
               "short_name" : "Piccadilly Circus",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "London",
               "short_name" : "London",
               "types" : [ "postal_town" ]
            },
            {
               "long_name" : "Greater London",
               "short_name" : "Greater London",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "England",
               "short_name" : "England",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Regno Unito",
               "short_name" : "GB",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "W1J 9HP",
               "short_name" : "W1J 9HP",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Piccadilly Circus Station, London W1J 9HP, Regno Unito",
         "geometry" : {
            "location" : {
               "lat" : 51.510121,
               "lng" : -0.1341683
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 51.51146998029149,
                  "lng" : -0.132819319708498
               },
               "southwest" : {
                  "lat" : 51.50877201970849,
                  "lng" : -0.135517280291502
               }
            }
         },
         "place_id" : "ChIJvVRe4NMEdkgRw3WgQO_J9KM",
         "types" : [
            "establishment",
            "point_of_interest",
            "train_station",
            "transit_station"
         ]
      }
   ],
   "status" : "OK"
}

【讨论】:

  • 正确!地址“Piccadilly Circus, London, UK”需要编码...感谢您的帮助!
  • 不客气,古斯塔沃。如果您觉得我的回答有用,请接受并祝您编码愉快!
猜你喜欢
  • 1970-01-01
  • 2011-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-04
  • 1970-01-01
  • 2014-11-14
  • 2016-07-20
相关资源
最近更新 更多