Javascript 在JQuery中对这些变量使用设置值而不是随机值?
此演示在地图上的任意点创建标记: 我能对演示代码做的最小修改是什么,这样我就可以指定点的经度和纬度,而不是让它们随机出现 请注意,我的确切代码与链接中的演示略有不同:Javascript 在JQuery中对这些变量使用设置值而不是随机值?,javascript,jquery,Javascript,Jquery,此演示在地图上的任意点创建标记: 我能对演示代码做的最小修改是什么,这样我就可以指定点的经度和纬度,而不是让它们随机出现 请注意,我的确切代码与链接中的演示略有不同: $('#test1').gmap3( { action: 'init', center:{ lat:44.797916, lng:-93.278046 }, onces: { bounds_c
$('#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());
}
}
});
}
}
}
);
});
$('test1').gmap3(
{操作:'init',
中心:{
拉脱维亚:44.797916,
液化天然气:-93.278046
},
onces:{
边界_已更改:函数(){
$(本文件)。gmap3({
操作:'getBounds',
回调:函数(边界){
如果(!bounds)返回;
var soutwest=bounds.getsoutwest(),
东北=边界。getNorthEast(),
lngSpan=东北.lng()-西南.lng(),
latSpan=东北.lat()-西南.lat(),
我
对于(i=0;i<10;i++){
添加($(this),i,soutwest.lat()+latSpan*Math.random(),soutwest.lng()+lngSpan*Math.random());
}
}
});
}
}
}
);
});
这是我实际使用的代码。我知道这有点骇人,但这只是一个演示。
你应该改变
addPantoMarker($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
有你们想要的价值
addPantoMarker($(this), i, southWest.lat() + latSpan * yourLat, southWest.lng() + lngSpan * yourLong);
你应该改变
addPantoMarker($(this), i, southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
有你们想要的价值
addPantoMarker($(this), i, southWest.lat() + latSpan * yourLat, southWest.lng() + lngSpan * yourLong);
此处是向随机位置添加标记的位置:
addPantoMarker($(this),i,soutwest.lat()+latSpan*Math.random(),soutwest.lng()+lngSpan*Math.random())代码>
使用所需坐标更改第二个和第三个参数
例如:
addPantoMarker($(this),i,47.123,10.123)代码>此处是向随机位置添加标记的位置:
addPantoMarker($(this),i,soutwest.lat()+latSpan*Math.random(),soutwest.lng()+lngSpan*Math.random())代码>
使用所需坐标更改第二个和第三个参数
例如:
addPantoMarker($(this),i,47.123,10.123)代码>如果要创建自己的点集,请按照以下步骤进行操作:
// 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]);
}
}
});
}
}
}
);
//创建一组lat/lng点。用您自己的lat/lngs替换x/y
变量点=[
[x,y],
[x,y],
[x,y],
[x,y],
[x,y],
[x,y],
[x,y]
];
$(“#测试”).gmap3(
{操作:'init',
中间:[44.797916,-93.278046],
onces:{
边界_已更改:函数(){
$(本文件)。gmap3({
操作:'getBounds',
回调:函数(边界){
如果(!bounds)返回;
var soutwest=bounds.getsoutwest();
var northEast=bounds.getNorthEast();
var lngSpan=northEast.lng()-soutwest.lng();
var latSpan=northEast.lat()-soutwest.lat();
对于(变量i=0;i
如果您想创建自己的一组点,您需要按照以下步骤进行操作:
// 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]);
}
}
});
}
}
}
);
//创建一组lat/lng点。用您自己的lat/lngs替换x/y
变量点=[
[x,y],
[x,y],
[x,y],
[x,y],
[x,y],
[x,y],
[x,y]
];
$(“#测试”).gmap3(
{操作:'init',
中间:[44.797916,-93.278046],
onces:{
边界_已更改:函数(){
$(本文件)。gmap3({
操作:'getBounds',
回调:函数(边界){
如果(!bounds)返回;
var soutwest=bounds.getsoutwest();
var northEast=bounds.getNorthEast();
var lngSpan=northEast.lng()-soutwest.lng();
var latSpan=northEast.lat()-soutwest.lat();
对于(变量i=0;i
这是错误的。他想指定精确的坐标。您刚刚用另一个值yourLat
和yourLong
替换了Math.random()。我没有addPantoMarker,我更新了我的问题。这是错的。他想指定精确的坐标。您刚刚用另一个值yourLat
和yourLong
替换了Math.random()。我没有addPantoMarker,我更新了我的问题。谢谢,我的代码实际上和我发布的有点不同。我没有addPantoMarker,我更新了我的问题。谢谢你,它的名字叫add
。我更改了代码以反映这一点。对不起,我的代码实际上与我发布的代码有点不同。我没有addPantoMarker,我更新了我的问题。谢谢你,它的名字叫add
。我更改了代码以反映这一点。对不起,我的代码实际上与我发布的代码有点不同。我没有addPantoMarker,我更新了我的问题。谢谢,我的代码实际上和我发布的有点不同。我没有addPantoMarker,我更新了我的问题。谢谢我意识到我粘贴了错误的代码,我更新了我的问题。谢谢我意识到我粘贴了错误的代码,我更新了我的问题。谢谢