无论我在哪里点击路线,我都想画一个圆圈.我找了一个关于如何使路由可点击的解决方案,但找不到任何有用的东西......下面是我的代码.当我点击路线但没有创建圆圈时,我没有收到任何错误.
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请求中 …
我需要在地图方向上填充以下数据
dataset 1
[
[lat, lon],
[lat, lon],
[lat, lon],
],
dataset 2
[
[lat, lon],
[lat, lon],
[lat, lon],
],
So On ...
Run Code Online (Sandbox Code Playgroud)
所有数据集都应具有具有唯一颜色的路线,并且任何数据集都可以超过 8 个航点限制。我能够通过遵循https://lemonharpy.wordpress.com/2011/12/15/working-around-8-waypoint-limit-in-google-maps-directions-api/等在线教程来修复 8 个路点限制在 Google 地图 v3 中绘制超过 8 个航点。
但我发现没有办法为每个数据集获取不同颜色的路线。
这是我的代码
<style>
#map {
height: 1080px;
width: 100%;
border: 1px solid #000;
}
</style>
<div id="map"></div>
<script>
function initMap() {
//console.log("sdsfsd");
map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: {lat: 28.6247, lng: 77.3731},
disableDefaultUI:true,
//28.6247375!4d77.3731819
});
var directionsService = new …Run Code Online (Sandbox Code Playgroud)