javascript - 无法在代码中包含 Google map 标记?

标签 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);

我根据在动画折线和动画符号上找到的其他代码片段形成了它,并且它运行得很好。但是,每当我尝试在代码中添加标记(并且我尝试在很多地方添加它)时,代码永远不会初始化,有时不显示任何内容,有时只显示 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({

参见:http://jsfiddle.net/yghoy4ka/

关于javascript - 无法在代码中包含 Google map 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122696/

相关文章:

javascript - 在不调用函数的情况下获取函数参数名称?

Javascript函数来显示所遵循的城市的路线

javascript - 智能手机设备上的地理定位无法运行

java - 在谷歌地图 V2 ... fragment.getMap() 返回 null

xml - 我如何从 Google Maps API 获取行车时间?

javascript - PHP 错误此站点需要启用 JavaScript

javascript - 如何使用javascript获取浏览器显示高度和宽度

ios - 如何在 Objective C 中的 Google map 上动态创建多个图钉

google-maps - 确定坐标是否在 Google map 范围内?

javascript - 当我打印我的网站时,有什么方法可以使我的谷歌地图相同