javascript 使用javascript获取纬度和经度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16116768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get the latitude and longitude using javascript
提问by Hyman Php
I have a textboxin my page which gets a locationname and buttonwith text getLat&Long. Now on clickingmy button I have to show an alertof latitudeand longitudeof the location in the textbox. Any suggestion?
please dont give me suggestion as googleapis b'coz its some stage limitations after this limit want to pay for this.
this is my try with googleapis:-
我有一个textbox在我的网页,其中获得一个location名称和button文本getLat&Long。现在,在clicking我的按钮,我要表现出alert的latitude和longitude在的位置textbox。有什么建议吗?
请不要给我建议,因为 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>
thanks.
谢谢。
回答by Rodrigo5244
Getting the latitude and longitude from an address or location name (Geocoding) is complicated, so a third party service like google api is going to be needed.
从地址或位置名称(地理编码)获取纬度和经度很复杂,因此将需要像 google api 这样的第三方服务。

