我想在一个地图上绘制几个点,但是我也想计算每个点之间的里程数,但是由于getLatLng是异步的,我无法做到。
我真的不想设置一个仲裁计时器,所以无论如何我可以实现回调或强制getLatLng同步行为吗?
这是我的代码:
function showAddress(markers, intNumber)
{
intNumber++;
if (geocoder)
{
geocoder.getLatLng(markers,
function(point)
{
if (!point)
{
// alert(markers + " not found");
}else
{
var icon = new GIcon();
icon.image = "images/numbers/marker"+intNumber+".png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(20, 34);
icon.infoWindowAnchor = new GPoint(15, 34)
map.setCenter(point, 5);
var marker = new GMarker(point, icon);
GEvent.addListener(marker, 'click',
function()
{
marker.openInfoWindowHtml(markers);
});
map.addOverlay(marker);
if(objPreviousPoint != null)
{
miles += MetersMiles * (point.distanceFrom(objPreviousPoint));
var polyline = new GPolyline([ objPreviousPoint, point], "#FF0000", 3);
map.addOverlay(polyline);
}
objPreviousPoint = point;
}
});
}
}
for (i in arrLocations)
{
showAddress(arrLocations[i], i);
}
有什么想法吗?
由于
TheBounder。