2016-11-24 99 views
-3

我已經在很多網站上搜索了一個解決方案,但沒有一個人工作。如何在JavaScript中找到經緯度的城市名稱?

由於時間我試圖通過使用緯度和經度值,我將從一個輸入框讓我xy變量來獲得城市的名稱,但沒有例子的工作。

我也讀過谷歌地圖API,但沒有用。

我已經有一個API密鑰。

你也許有任何解決方案?

這個例子,我從網站上得到了和嘗試,但沒有成功:

function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates 
    var geocoder = new google.maps.Geocoder; 
    var latlng = {lat: parseFloat(x), lng: parseFloat(y)}; 

    geocoder.geocode({'location': latlng}, function(results, status) { 
     if (status === google.maps.GeocoderStatus.OK) { 
     // ... 
     } else { 
      window.alert('No results found'); 
     } 
     } else { 
      window.alert('Geocoder failed due to: ' + status); 
     } 
    }); 
} 
+1

試試這個:http://stackoverflow.com/questions/67975 69/get-city-name-using-geolocation – Bassie

+0

http://www.geocodezip.com/v3_GoogleEx_geocoding-reverse2postcodeD.html – geocodezip

+0

哇這就是謝謝:)喜歡這個網站! – sinanto

回答

相關問題