小编php*_*beg的帖子

如何获得通过输入框输入的城市/国家的经度和纬度?

我有这个代码,

<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>
Run Code Online (Sandbox Code Playgroud)

这将在小对话框中给出输入城市的纬度和经度.但我需要在同一页面或父页面中.请帮我

html jquery google-maps

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-maps ×1

html ×1

jquery ×1