此演示在地图上的随机点创建标记: http://gmap3.net/examples/pan-to-markers.html
我可以对演示代码进行最小的修改,这样我可以指定点的经度和纬度而不是随机的吗?
注意我所拥有的确切代码与链接中的演示略有不同:
$('#test1').gmap3(
{ action: 'init',
center:{
lat:44.797916,
lng:-93.278046
},
onces: {
bounds_changed: function(){
$(this).gmap3({
action:'getBounds',
callback: function (bounds){
if (!bounds) return;
var southWest = bounds.getSouthWest(),
northEast = bounds.getNorthEast(),
lngSpan = northEast.lng() - southWest.lng(),
latSpan = northEast.lat() - southWest.lat(),
i;
for (i = 0; i < 10; i++) {
add($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
}
}
});
}
}
}
);
});
这是我实际使用的代码。我知道它的hacky,但这只是一个演示。 http://smartpeopletalkfast.co.uk/gmap/demo/overlay.html
答案 0 :(得分:2)
如果你想创建自己的一组积分,你需要按照以下几点做点什么:
// create a set of lat/lng points. Replace x/y with your own lat/lngs
var points = [
[x, y],
[x, y],
[x, y],
[x, y],
[x, y],
[x, y],
[x, y]
];
$('#test').gmap3(
{ action: 'init',
center:[44.797916,-93.278046],
onces: {
bounds_changed: function(){
$(this).gmap3({
action:'getBounds',
callback: function (bounds){
if (!bounds) return;
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
for (var i = 0; i < points.length; i++) {
// instead use the points you previously defined
add($(this), i, points[i][0], points[i][1]);
}
}
});
}
}
}
);
答案 1 :(得分:1)
你应该改变
addPantoMarker($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
带有你想要的价值
addPantoMarker($(this), i, southWest.lat() + latSpan * yourLat, southWest.lng() + lngSpan * yourLong);
答案 2 :(得分:0)
您可以在此处向随机位置添加标记:
addPantoMarker($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
使用所需坐标更改第二个和第三个参数。
示例:
addPantoMarker($(this), i, 47.123, 10.123);