可以'不要在代码中包含谷歌地图标记

Can't include a Google Maps marker in code?

本文关键字:包含 谷歌 地图 图标 代码 可以      更新时间:2023-09-26

以下是我一直在做的工作: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);

我从我在动画多段线和动画符号中发现的其他代码片段中形成了它,它运行得很好。然而,每当我尝试向代码添加标记时(我尝试在许多地方添加它),代码从不初始化,有时不显示任何内容,有时只显示映射。有人能帮我弄清楚我做错了什么吗?

var sourceImage = 'source-map-marker.png';
new mrker = new google.maps.Marker({
    position: start,
    map: map,
    icon: sourceImage
    });

删除mrker之前的new并替换为varvar mrker = new google.maps.Marker({

请参阅:http://jsfiddle.net/yghoy4ka/