function initialize()
{
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(21.7679, 78.8718),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var count=0;
var isCreateHeadPoint = true;
var headMarker, tailMarker;
google.maps.event.addListener(map, 'click', function(e) {
if(count<2)
{
if(isCreateHeadPoint)
{
var headmarker = new google.maps.Marker({
position: e.latLng,
draggable:true,
map: map
});
isCreateHeadPoint=false;
count++;
}
else
{
var tailmarker = new google.maps.Marker({
position: e.latLng,
draggable:true,
map: map
});
count++;
}
}
google.maps.event.addListener(headmarker,'click', function(event)
{
infowindow = new google.maps.InfoWindow({
map: map,
content: "coordinates:"+event.latLng.toUrlValue(),
position: event.latLng,
});
infowindow.open(map, headmarker);
});
google.maps.event.addListener(tailmarker,'click', function(event)
{
infowindow = new google.maps.InfoWindow({
map: map,
content: "coordinates:"+event.latLng.toUrlValue(),
position: event.latLng,
});
infowindow.open(map, tailmarker);
});
});
}
我放置了 2 个可拖动的标记,我必须计算这两个标记之间的路线。