繁体   English   中英

使用javascript获取经度和纬度

[英]get the latitude and longitude using javascript

我的页面上有一个textbox ,其中包含一个location名称和带有文本getLat&Long button 现在clicking我的按钮,我必须在textbox显示该位置的latitudelongitude alert 有什么建议吗?
请不要给我建议,因为googleapis b'coz在此限制要为此支付费用后会出现一些阶段限制。 这是我对googleapis尝试:-

<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>

谢谢。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM