无论我在哪里点击路线,我都想画一个圆圈.我找了一个关于如何使路由可点击的解决方案,但找不到任何有用的东西......下面是我的代码.当我点击路线但没有创建圆圈时,我没有收到任何错误.
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
//direction service request here...
google.maps.event.addListener(directionsDisplay, 'click', function(event) {
var routeClick = new google.maps.Circle({
center: event.latLng, //center where you click
radius: 500,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#0000FF",
fillOpacity: 0.4
});
routeClick.setMap(map);
});
Run Code Online (Sandbox Code Playgroud)
更新:
基于Geocodezip脚本创建自己的方向折线的工作代码http://www.geocodezip.com/v3_directions_custom_iconsC.html和官方API示例https://developers.google.com/maps/documentation/javascript/examples/elevation-paths
// Draw the path
function drawPath(path) {
// Display a polyline of the elevation path.
var pathOptions = {
path: path,
strokeColor: '#0000CC',
strokeWeight: 5,
opacity: 0.4,
map: map
}
routePolyline = new google.maps.Polyline(pathOptions);
}
Run Code Online (Sandbox Code Playgroud)
然后在我添加的directionService请求中 …
我想知道是否有人知道如何使用谷歌地图api找到两个地方之间的路线的中点.我不想要地理中心,而是沿着行驶距离的中点.我是Javascript和谷歌地图api的新手,所以如果你可以包含一个演示或一些代码与你的答案,这将是非常有帮助的.最终结果将输出纬度和经度,并表示类似于本网站的内容:http://www.geomidpoint.com/meet/.感谢你的帮助!