这是我一直在做的事情:http://jsfiddle.net/sumeetbansal/morxcuxc/ .
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(22.291, 53.027),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
el = document.getElementById('map-canvas');
var map = new google.maps.Map(el,mapOptions);
// 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'
};
var start = new google.maps.LatLng (32.291, 3.027);
var endpt = new google.maps.LatLng (12.291, 103.027);
var coord = [start, endpt];
var line = new google.maps.Polyline({
path: coord,
strokeColor: '#393',
strokeOpacity: 1,
strokeWeight: 1,
geodesic: true,
map: map,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
});
animateCircle();
var step = 0;
var numSteps = 250; //Change this to set animation resolution
var timePerStep = 1; //Change this to alter animation speed
var interval = setInterval(function() {
step += 1;
if (step > numSteps) {
clearInterval(interval);
} else {
var theMotion = google.maps.geometry.spherical.interpolate(start,endpt,step/numSteps);
line.setPath([start, theMotion]);
}
}, timePerStep);
}
function animateCircle() {
var count = 0;
window.setInterval(function() {
count = (count + 1) % 200;
var icons = line.get('icons');
icons[0].offset = (count / 2) + '%';
line.set('icons', icons);
}, 20);
}
google.maps.event.addDomListener(window, 'load', initialize);
我根据在动画折线和动画符号上找到的其他代码片段形成了它,并且它运行得很好。但是,每当我尝试在代码中添加标记(并且我尝试在很多地方添加它)时,代码永远不会初始化,有时不显示任何内容,有时只显示 map 。有人可以帮我找出我做错了什么吗?
var sourceImage = 'source-map-marker.png';
new mrker = new google.maps.Marker({
position: start,
map: map,
icon: sourceImage
});
最佳答案
删除mrker
之前的new
并替换为var
:
var 标记 = new google.maps.Marker({
关于javascript - 无法在代码中包含 Google map 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122696/