簡體   English   中英

當Google Maps顯示位置時,Google Maps API給出零結果

[英]Google maps API gives zero results when Google Maps shows the location

我試圖在Google Maps頂部創建類似的自動填充字段。 地理編碼和自動完成API(v3)可以很好地運行,除非您嘗試查找不在位置信息庫中的位置。 例如:如果您在Google地圖上搜索“ campus de campolide”,它將“ Universidade Nova de Lisboa”在地圖上居中,並在URL中顯示坐標。 但是它沒有顯示標記。 我猜谷歌地圖沒有這個地方的地址,並且“預測”了一個大概的位置。 (可能正確,可能正確)

如果我嘗試在代碼中復制此代碼:

if($('#autocomplete').val() !== ""){
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({address: $('#autocomplete').val()}, function(result, status){
    console.log(result);
  });
}

我總是得到ZERO_RESULTS,因為顯然它無法檢索地址。 我不能找到地址,但我真的很希望URL中Google地圖中顯示的地理坐標。 如何使用API​​實現此目標?

var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address':"your text" }, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {                     
    console.log(results[0].geometry.location.lat()));                          
  } 
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM