I use a mousemove listener on Google Maps, while I want handle the click event too.
var path = new google.maps.MVCArray;
...
line = new google.maps.Polyline({
map: map,
pat开发者_如何转开发h: new google.maps.MVCArray([path]),
});
google.maps.event.addListener(map, 'click', function(event) {
path.push(event.latLng);
});
google.maps.event.addListener(map, 'mousemove', function(event) {
if (path.getLength() > 1) path.setAt(path.getLength()-1,event.latLng);
});
I want to follow the mouse with the line, but if the user click on the map, push the polyline's array. But the click event doesn't work... Any idea?
I think there is a small bug in your code:
On line 5 it should read
path: path,
instead of
path: new google.maps.MVCArray([path]),
Reason: Your var path is already an MCVArray and the property path of PolylineOptions expects just an MVCArray, but you supply it with an MVCArray inside a normal array inside an MVCArray.
This prevents the code following from pushing the coordinates to the correct array.
精彩评论