【发布时间】:2017-07-06 13:19:20
【问题描述】:
我有以下代码在 13 个 GPS 坐标之间绘制折线。折线绘制正确。我试图在距折线起点 5 公里的距离上放置一个标记。我正在尝试使用 v3_epoly 中的 GetPointAtDistance() 但是当我引用它时,使用
flightPath.GetPointAtDistance(5000);
就在 flightPath.setMap(map); 之前但折线消失了,没有新的标记出现。我正在谈论为什么这不起作用,任何帮助将不胜感激
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>VM 2</title>
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript" src="scripts/v3_epoly.js"></script>
</head>
<body style="font-family: Arial; font-size: 12px;">
<div style="width: 100%;" id="mapDiv">
<div id="map" style="width: 70%; height: 600px; float: left;margin:0px;color:black;"></div>
<div id="panel" style="width: 30%; float: left;margin:0px;"></div>
</div>
<script type="text/javascript">
var locations = [
{
title: "Point 1",
lat : -0.004259,
lng : 36.96367099999998,
},
{
title: "Point 2",
lat : 0.3606,
lng : 36.782,
},
{
title: "Point 3",
lat : 0.3145033,
lng : 36.9755982,
},
{
title: "Point 4",
lat : 0.2336305,
lng : 37.3166943,
},
{
title: "Point 5",
lat : 0.2253856,
lng : 37.440852,
},
{
title: "Point 6",
lat : 0.0880828,
lng : 38.1899782,
},
{
title: "Point 7",
lat : -0.2356904,
lng : 36.8766403,
},
{
title: "Point 8",
lat : -0.4169027,
lng : 36.6666989,
},
{
title: "Point 9",
lat : -0.3666667,
lng : 36.0833333,
},
{
title: "Point 10",
lat : -1.4065513,
lng : 34.906551,
},
{
title: "Point 11",
lat : -1.3666667,
lng : 36.8333333,
},
{
title: "Point 12",
lat : -2.55143,
lng : 37.79738,
},
{
title: "Point 13",
lat : -3.3951791,
lng : 37.9572584,
},
];
function initialize() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom : 2,
center : new google.maps.LatLng(10, -10),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
map : map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i].title);
infowindow.open(map, marker);
}
})(marker, i));
}
var flightPath = new google.maps.Polyline({
path : locations,
geodesic : true,
strokeColor : '#5589ca',
strokeOpacity: 1.0,
strokeWeight : 2
});
var latlngex = new google.maps.LatLng(-4.0434771,39.6682065);
var titleex = "Test Marker";
createMarker(map,latlngex,titleex);
flightPath.setMap(map);
}
function createMarker(map, latlng, title){
var marker = new google.maps.Marker({
position:latlng,
map:map,
title: title,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
});
}
google.maps.event.addDomListener(window, "load", initialize);
</script>
</body>
【问题讨论】:
标签: google-maps google-maps-api-3 distance marker jscript