【问题标题】:get the latitude and longitude using javascript使用javascript获取纬度和经度
【发布时间】:2013-04-20 05:03:24
【问题描述】:

我的页面中有一个textbox,它有一个location 名称和button 与文本getLat&Long。现在在clicking 我的按钮上,我必须在textbox 中显示latitudealertlongitude 的位置。有什么建议吗?
请不要给我建议,因为 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>

谢谢。

【问题讨论】:

  • 你能显示一些代码吗?
  • @plalx 添加我的代码。但我使用googleapis 我不喜欢这个任何其他想法然后建议。谢谢。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-25
    • 2016-09-29
    • 1970-01-01
    • 2020-04-29
    • 2013-05-08
    • 1970-01-01
    相关资源
    最近更新 更多