[英]How can i do geocoding in javascript to get lat and long?
This is how i am trying, but i am not getting any response. 这是我正在尝试的方式,但是我没有得到任何回应。 What could be wrong ?
有什么问题吗?
API used: 使用的API:
<script src="http://maps.google.com/maps?file=api&v=2&key=***&sensor=false"
type="text/javascript"></script>
function initialize() {
var addrLookup = 'San Diego , CA 92101';
var geoCoder = new google.maps.Geocoder();
var geoRequest = { address: addrLookup };
geoCoder.geocode(geoRequest,function(results,status){
window.alert("response");
console.log(status);
});
}
Slightly modify your script: 稍微修改脚本:
<html>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
var addrLookup = 'San Diego , CA 92101';
var geoCoder = new google.maps.Geocoder();
var geoRequest = { address: addrLookup };
geoCoder.geocode(geoRequest,function(results,status){
console.log('latitude: ',results[0].geometry.location.lat());
console.log('longitude: ',results[0].geometry.location.lng());
});
}
</script>
<body onload="initialize()">
</body></html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.