// This example adds an animated symbol to a polyline.
var line;
var marker;
var lineCoordinates;
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(20.291, 153.027),
zoom: 6,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
lineCoordinates = [
new google.maps.LatLng(22.291, 153.027),
new google.maps.LatLng(18.291, 153.027)
];
// Define the symbol, using one of the predefined paths ('CIRCLE')
// supplied by the Google Maps JavaScript API.
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#393'
};
// Create the polyline and add the symbol to it via the 'icons' property.
line = new google.maps.Polyline({
path: lineCoordinates,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
map: map
});
animateCircle();
}
// Use the DOM setInterval() function to change the offset of the symbol
// at fixed intervals.
function animateCircle() {
var infowindow = new google.maps.InfoWindow();
var count = 0;
window.setInterval(function() {
count = (count + 1) % 200;
var icons = line.get('icons');
icons[0].offset = (count/2) + '%';
line.set('icons', icons);
var position = google.maps.geometry.spherical.interpolate(lineCoordinates[0], lineCoordinates[1], (count/200));
if (!marker) {
marker = new google.maps.Marker({
position: position,
map: map
});
infowindow.setContent(marker.getPosition().toUrlValue(6));
infowindow.open(map, marker);
} else {
marker.setPosition(position);
}
infowindow.setContent(marker.getPosition().toUrlValue(6));
}, 20);
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map-canvas {
height: 500px;
width: 500px;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&ext=.js"></script>
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>
爲什麼有人投票決定關閉這爲_ 「這個問題並不顯得有關編程」 _?似乎對我來說很關鍵 – duncan
@duncan,而不是我,但被標記爲:**尋求調試幫助的問題(「爲什麼不是這個代碼工作?」)必須包括所需的行爲,特定的問題或錯誤以及在問題本身中重現它所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建一個最小化,完整和可驗證的示例**我猜投票人想要一個小提琴或一些MCV示例 –
用戶不需要調試幫助或演示破損的代碼,他們想知道如何實現一些新功能。 – duncan