2015-12-21 29 views
-1

我面臨與谷歌地理編碼API服務奇怪的問題。我要求 「48 spottiswoode住宅,spottiwood公園,新加坡088660」地址API分別返回拉= 1.345871和lng = 103.75089739999999。 但是,谷歌地圖顯示lat = 1.2752757和lng = 103.8346363爲相同的地址。谷歌地圖和谷歌地理編碼服務返回不同的緯度和經度爲相同的地址

請求URL:

http://maps.googleapis.com/maps/api/js/GeocodeService.Search?4sSingapore%2C%20088660&7sUS&8m2&1scountry&2sSingapore&9sen-US&callback=xdc._wo127a&token=117480

響應:

{ "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "Singapore", 
       "short_name" : "Singapore", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Bukit Batok", 
       "short_name" : "Bukit Batok", 
       "types" : [ "neighborhood", "political" ] 
      }, 
      { 
       "long_name" : "Singapore", 
       "short_name" : "Singapore", 
       "types" : [ "locality", "political" ] 
      }, 
      { 
       "long_name" : "Singapore", 
       "short_name" : "SG", 
       "types" : [ "country", "political" ] 
      } 
     ], 
     "formatted_address" : "Singapore, Singapore", 
     "geometry" : { 
      "location" : { 
       "lat" : 1.345871, 
       "lng" : 103.7508974 
      }, 
      "location_type" : "GEOMETRIC_CENTER", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 1.347219980291502, 
        "lng" : 103.7522463802915 
       }, 
       "southwest" : { 
        "lat" : 1.344522019708498, 
        "lng" : 103.7495484197085 
       } 
      } 
     }, 
     "partial_match" : true, 
     "place_id" : "ChIJOfDA4T8Q2jERL48IW_56xww", 
     "types" : [ "route" ] 
     } 
    ], 
    "status" : "OK" 
} 

在此先感謝。

回答

2

所提供的地址似乎不正確(正確的地址是48史卜迪士公園路,Singapur 088660

要得到的結果也類似maps.google.com(即使是錯誤的地址)你而應使用Places.TextSearch

var map; 
 
var service; 
 
var infowindow; 
 

 
function init() { 
 
    var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316); 
 

 
    map = new google.maps.Map(document.getElementById('map'), { 
 
    center: pyrmont, 
 
    zoom: 19 
 
    }); 
 

 
    var request = { 
 
    query: '48 spottiswoode residences, spottiwood park, Singapore 088660' 
 
    }; 
 

 
    service = new google.maps.places.PlacesService(map); 
 
    service.textSearch(request, function callback(results, status) { 
 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
 
     var ll = results[0].geometry.location; 
 
     new google.maps.Marker({ 
 
     map: map, 
 
     position: ll 
 
     }); 
 
     
 
     map.setCenter(ll); 
 
    } 
 
    }); 
 
} 
 

 

 
google.maps.event.addDomListener(window, 'load', init);
html, 
 
body, 
 
#map { 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0 
 
}
<div id="map"></div> 
 
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places"> 
 
</script>

+0

地址就可以了。去谷歌上查詢。 –

+0

當我[google it](https://maps.google.de/maps?q=48+spottiswoode+residences,+spottiwood+park,+Singapore+088660&oe=utf-8&gws_rd=cr&um=1&ie=UTF-8&sa= X&ved = 0ahUKEwjGlLvt0u7JAhWCYA8KHfG1BGYQ_AUIBygB)返回的地址是** 48 Spottiswoode Park Road,Singapur 088660 **,不是** 48 spottiswoode住宅,spottiwood park,新加坡088660 ** –

相關問題