我尝试过在折线地图制作器上添加标题,但它对我不起作用。我不明白出了什么问题,或者为什么它不能正常工作。我尝试添加标题或说明,但无法使其正常工作。它不会在控制台中给我错误,但是如果我单击它,则不会显示标题。 function initialize() { var map = new google.maps.Map(document.getElementById('map-canvas'), { center: { lat: 42.9994443, lng: -0.0107599}, zoom: 12 }); var fromMarker = new google.maps.Marker({ map: map, position: { lat: 43.1002647, lng: -0.0423151 }, title: 'Hello World!' }); var toMarker = new google.maps.Marker({ map: map, position: { lat: 42.8906, lng: -0.115006 }, title: 'Hello World!' }); var ds = new google.maps.DirectionsService(); ds.route({ origin: fromMarker.getPosition(), destination: toMarker.getPosition(), travelMode: google.maps.TravelMode.DRIVING, unitSystem: google.maps.UnitSystem.METRIC }, function (result, status) { if (status == google.maps.DirectionsStatus.OK) { console.log(result); new google.maps.Polyline({ map: map, path: result.routes[0].overview_path, strokeOpacity: 1.0, strokeWeight: 2, geodesic: true, icons: [{ icon: {path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW}, offset: '100%', repeat: '40px' }] }); var fullPath = []; result.routes[0].legs.forEach(function (leg) { leg.steps.forEach(function (step) { fullPath = fullPath.concat(step.path); new google.maps.Polyline({ map: map, path: step.path, strokeColor: "red", strokeWeight: 1 }); }); }); } }); } google.maps.event.addDomListener(window, 'load', initialize);
1 回答

呼唤远方
TA贡献1856条经验 获得超11个赞
标记标题在悬停时显示。如果要在单击时显示信息窗口,则应添加如下所示的内容:
var infowindow = new google.maps.InfoWindow({
content: "<span>Your title</span>"
});
google.maps.event.addListener(fromMarker, 'click', function() {
infowindow.open(map, fromMarker);
});
有关 Info Windows: https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple 的更多信息
添加回答
举报
0/150
提交
取消