我正在使用Google Geocoder将地址转换为一个坐标,该坐标会添加到我想在googleMaps上映射的前一个坐标数组中。除了我使用GeoCoder在数组中添加的值之外,所有值都被映射。有人可以帮忙吗?
Following is my code : coordinatesArray is the array in which I push the new value computed from my code.
var geocoder = new google.maps.Geocoder();
var address = route.fullname;
var latitude , longitude;
geocoder.geocode({'address' : address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
alert("Name : " + address + " : " + latitude + " : "
+ longitude);
coordinatesArray.push(new google.maps.LatLng(latitude,longitude));
}});
function initialize() {
var mapOptions = {
zoom : 8,
disableDefaultUI : true,
center : coordinatesArray[0],
mapTypeId : google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var mapPath = new google.maps.Polyline({
path : coordinatesArray,
geodesic : true,
strokeColor : 'green',
strokeOpacity : 1.0,
strokeWeight : 2
});
mapPath.setMap(map);
}
我做错了什么建议?