代码中不能包含Google地图标记?

时间:2015-06-29 18:13:22

标签: javascript google-maps google-maps-api-3 jquery-animate

以下是我一直致力于: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
    });

1 个答案:

答案 0 :(得分:2)

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

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