그것을 밖으로 시도 :
//observe click
google.maps.event.addListener(map,'click',function(e){
//if there is no Polyline-instance, create a new Polyline
//with a path set to the clicked latLng
if(!line){
line=new google.maps.Polyline({map:map,path:[e.latLng],clickable:false});
}
//always push the clicked latLng to the path
//this point will be used temporarily for the mousemove-event
line.getPath().push(e.latLng);
new google.maps.Marker({map:map,position:e.latLng,
draggable:true,
icon:{url:'http://maps.gstatic.com/mapfiles/markers2/dd-via.png',
anchor:new google.maps.Point(5,5)}})
});
//observe mousemove
google.maps.event.addListener(map,'mousemove',function(e){
if(line){
//set the last point of the path to the mousemove-latLng
line.getPath().setAt(line.getPath().getLength()-1,e.latLng)
}
});
데모 : http://jsfiddle.net/doktormolle/4yPDg/
참고 : 코드의이 부분이 중복 :
var coord = new google.maps.LatLng(option.latLng.lb, option.latLng.mb);
option.latLng
이미 google.maps.LatLng
이다, 너는 사용할지도 모른다. 그것은 바로
var coord = option.latLng;
또한 : 이러한 속성의 이름이 고정되지 않고 다음 세션에서 변경 될 수 있습니다, mb
또는 lb
처럼이 문서화되지 않은 속성을 사용해서는 안됩니다.
클릭 내에서 mousemove 이벤트를 중첩하지 않은 것으로 나타났습니다. 중첩 된 이벤트 리스너는 일반적으로 나쁜 아이디어입니까? – Skitterm
나는 그런 말을하지 않을 것이다. (당신이 올바르게 사용하고 중복 될 때 지우는 한) –