2013-04-20 124 views
1

我在我的頁面有一個textbox,得到location名稱和button並帶有文本getLat&Long。現在在clicking我的按鈕我必須顯示textbox中位置的latitudelongitudealert。任何建議?
請不要給我建議作爲googleapis b'coz它的一些階段限制後,此限制要支付這一點。 這是我嘗試用googleapis: -使用javascript獲取緯度和經度

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 
function myIP(){ 
$("#btn").click(function(){ 
      var geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 'address': '#city'}, function(results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
      alert("location : " + results[0].geometry.location.lat() + " " +results[0].geometry.location.lng()); 
      } else { 
      alert("Something got wrong " + status); 
      } 
     }); 
}); 
} 
</script> 
</head> 
<body onload="myIP()"> 
<input type="text" id= "city"> 
<input id="btn" type="button" value="get Lat&Long" /> 
</body> 
</html> 

感謝。

+0

你能展示一些代碼嗎? – plalx 2013-04-20 05:04:40

+0

@plalx添加我的代碼。但我使用'googleapis'我不喜歡這個任何其他想法,然後建議。謝謝。 – 2013-04-20 05:08:21

回答

0

從地址或地點名稱(地理編碼)獲取緯度和經度很複雜,因此需要第三方服務,如google api。