2016-11-21 27 views
0

以下HTTP請求給出了曼聯的位置,而不是實際的皮卡迪利馬戲團地址在倫敦:谷歌地圖API是給了曼徹斯特地址,而不是皮卡迪利廣場,倫敦,英國

https://maps.googleapis.com/maps/api/geocode/json?address=Piccadilly馬戲團,倫敦,英國

不過,當我在GoogleMaps中搜索「Piccadilly Circus,London,UK」時,我會在地圖中找到正確的位置。

下面是生成的JSON從API調用獲取:

{ 
    "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" 
} 
+0

您需要爲場所使用places API(如「Piccadill y馬戲團,倫敦,英國「),地理編碼API只能可靠地用於**郵政**地址。 – geocodezip

+0

[google maps api無法找到一個特定地址]的可能重複(http://stackoverflow.com/questions/34727425/google-maps-api-cant-find-one-specific-address) – geocodezip

+0

可能重複的[谷歌地圖標記不固定](http://stackoverflow.com/questions/34781932/google-map-marker-is-not-pinning-properly) – geocodezip

回答

0

我認爲問題是搜索鍵,其實下面的請求

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" 
} 
+0

正確!地址「英國倫敦皮卡迪利廣場」需要編碼......感謝您的幫助! Gustavo歡迎您來到 –

+0

。如果您發現我的答案有用,請接受它並快樂編碼! – ddb

相關問題