2012-12-15 59 views
1
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) { 
    $("#hello").html('Latitude: ' + data.latitude + 
     '<br /> Longitude: ' + data.longitude + 
     '<br /> Country: ' + data.address.country); 
});​ 

我經常使用上面的代碼來獲得latitude,longitude,country。但很多時候它不能正常工作更好的API來檢索經度/緯度數據

Latitude: 0 
Longitude: 0 
Country: Unknown 

是否有更好的API來獲得這些結果?

+0

您可能希望將問題的標題修改爲「更好的API來檢索經度/緯度數據」。 JSON數據非常含糊。 – Despertar

+0

如果你想從一個地址得到latlong,我推薦谷歌地圖。 https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses – Tim

+0

@ Despertar:我按照您的建議更改了標題 – underscore

回答

1

我一直使用smart-ip作爲HTML5地理定位API的後備,並且從來沒有真正遇到任何問題?

$.getJSON('http://smart-ip.net/geoip-json/?callback=?', function (data) { 
    $("#hello").html('Latitude: ' + data.latitude + 
     '<br /> Longitude: ' + data.longitude + 
     '<br /> Country: ' + data.countryName); 
});​ 

FIDDLE

谷歌也將是一個很好的選擇,但TOS谷歌地圖中明確規定:

不得使用或不顯示內容(從地圖API)一個 相應的谷歌地圖,除非您明確允許在Google Maps API文檔中或通過Google的 Google 執行此操作。