谁能帮我用这个javascript在googlemap中绘制折线......我已经在google-map中用标记绘制了两条折线,但问题是当我点击标记时,细节只打印在一个标记上...... ... 详细信息也没有完全打印在信息窗口内
我的代码如下
$(function(){
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(11.275387916698238, 75.8015380957031),
zoom: 12
}),
routes = [{origin:'p t usha road, kozhikode',
destination:'cooperative hospital, eranjipalam, kozhikode'
},
{origin:'IIM, Kozhikode',
destination:'VELLIMADUKUNNU, KOZHIKODE'
}
],
rendererOptions = {
preserveViewport: true,
map:map,
polylineOptions:{strokeColor:'#FF3300',
strokeWeight: 10},
suppressMarkers:true,
routeIndex:0
},
directionsService = new google.maps.DirectionsService();
$.each(routes,
function(i,obj){//<--anonymous function
var request = {
origin: obj.origin,
destination: obj.destination,
travelMode: google.maps.TravelMode.DRIVING
},
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
var lat = result.routes[0].legs[0].start_location.lat();
var lon = result.routes[0].legs[0].start_location.lng();
var lat1 = result.routes[0].legs[0].end_location.lat();
var lon1 = result.routes[0].legs[0].end_location.lng();
try{
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: map
});
var iws = new google.maps.InfoWindow({
content: "Home For Sale"
});
google.maps.event.addListener(marker, "click", function (e) { iws.open(map, marker); });
}catch(e){alert(e)}
try{
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat1, lon1),
map: map
});
var iw = new google.maps.InfoWindow({
content: "Home For Sale"
});
google.maps.event.addListener(marker, "click", function (e) { iw.open(map, marker); });
}catch(e){alert(e)}
directionsDisplay.setDirections(result);
}
});
});});