Hi, this is my google map code, when you click on the map, it will put
a marker, and if you put more than one marker, it will calculate the
path among the markers, but I got one problem, the path will add
repeatedly, I tried to use clearOverlays, but it also clear the
marker, can I clear the path but keep the marker?
function mapInit() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById('googlemap'));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var dirn1 = new GDirections(),
dirn2 = new GDirections(),
ret = new GClientGeocoder(),
arrCordinate = [];
// center map
ret.getLatLng('some address', function(point) {
if (!point) {
return 'cannot find address';
} else {
map.setCenter(point, 15);
}
});
// Listening to click map
GEvent.addListener(map, "click", function(overlay, point) {
if (!overlay) {
dirn1.loadFromWaypoints([point.toUrlValue(6),
point.toUrlValue(6)], {getPolyline: true});
}
});
// Listening to snap to the right coordinate when click map
GEvent.addListener(dirn1, "load", function() {
var p = dirn1.getPolyline().getVertex(0);
marker = new GMarker(p);
map.addOverlay(marker); // put the marker
arrCordinate.push(p); // remember the coordinate for
drawing the
line
// drawing the line
dirn2.loadFromWaypoints(arrCordinate, {getPolyline:
true});
});
// listening to drawing the line
GEvent.addListener(dirn2, 'load', function() {
map.addOverlay(dirn2.getPolyline());
});
} else {
alert('Browser is not compatible with Google Map');
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---