2017-05-03 126 views
-1

所以我通過谷歌地圖API發送到指定地址:谷歌地圖網頁後返回不同的VS API

蒂爾登村,02052

我可以在上面打字找到它在地圖上。當我使用下面的呼叫時,它會返回不準確的地圖位置。我錯過了什麼嗎?

function showAddress(address) { 
     if (geocoder) { 
     $('#mapblock').css('border','2px #CCC solid'); 
     geocoder.getLatLng(
      address, 
      function(point) { 
      if (!point) { 
          map.addControl(new GSmallZoomControl3D()); 

       alert(address + " not found"); 
      } else { 
       map.addControl(new GSmallZoomControl3D()); 
       map.setCenter(point, 13); 
       var marker = new GMarker(point); 
       map.addOverlay(marker); 
       //marker.openInfoWindow("test",{maxWidth:249}); 
      } 
      } 
     ); 
     } 
    } 

這是通過谷歌地圖的結果: Google Maps REsult.

API response/Geocode and Map result

下面是從API /地理編碼結果:

+0

您確定您從Google地圖中獲得了正確的位置嗎?你期待什麼結果?請提供一個演示問題(和您的預期結果)的[mcve]。你可能想看看:https://developers.google.com/maps/documentation/geocoding/best-practices – geocodezip

+0

好的,我會添加一些上面的帖子。 – BostonMacOSX

回答

0

有兩件事情要突出關於地址解析API請求在你的例子中。

  • '蒂爾登村02052'是不完整和模糊的。地理編碼服務在模糊查詢中效果不佳。我可以看到「蒂爾登村,02052」多個結果如圖我的截圖

enter image description here

你應該提供一個更精確的搜索字符串作爲本文件中提到:

https://developers.google.com/maps/faq#geocoder_queryformat

也看看最佳實踐,您可以找到解決模糊查詢的方法

https://developers.google.com/maps/documentation/geocoding/best-practices

  • 的Medfield的房委會,你是指作爲正確的結果有一個地址'30龐德街的Medfield,MA 02052,USA」,所以我希望'30龐德街,02052' 更準確地說:

https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D30%2520Pound%2520St%252C%2520%252002052