使用javascript获取经度和纬度

时间:2013-04-20 05:03:24

标签: javascript html google-api latitude-longitude city

我的页面中有一个textbox,其中location名称为button,文字getLat&Longclicking。现在,在alert我的按钮上,我必须在latitude中显示longitude textboxgoogleapis个位置。有什么建议吗?
请不要给我建议作为googleapis b'coz它的一些阶段限制后这个限制想要支付这个。 这是我尝试使用<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> : -

{{1}}

感谢。

1 个答案:

答案 0 :(得分:-1)

从地址或位置名称(地理编码)获取经度和纬度很复杂,因此需要像google api这样的第三方服务。