[英]Google Maps - using geocoder to get long/lat with javascript
[英]Google Map geocoder get long and lat
我试图通过for循环获得城市的长期和纬度。
现在我已经完成了我的编码,但仍然由于地理编码器是一个异步函数,一些东西不起作用(Map没有加载,标记没有显示)。 与地理编码器的输出我试图在MAP上显示标记。
function codeAddress(address, map, callback) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latLng = new google.maps.LatLng(results[0].geometry.location.lat().lat,results[0].geometry.location.lng());
var markerObj = new MarkerWithLabel({
position: latLng,
title:name,
labelContent: name,
labelClass:'marker-labels',
icon:markerImg
});
markerObj.setMap(map);
console.log(latLng);
return callback(map, latLng);
} else {
console.log('Geocode was not successful for the following reason: ' + status);
}
});
}
function initialize() {
var mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('googleMap'),mapOptions);
if ('' != markersAddress) {
for (var x=0; x<markersAddress.length; x++) {
var address = markersAddress[x].address;
var name = markersAddress[x].name;
codeAddress(address, map, function(map, latLng) {})
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
您使用的是MarkerWithLabel
但MarkerWithLabel
包含它
包括这两个文件
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js"></script>
请注意,这些文件的顺序很重要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.