【发布时间】:2020-09-17 18:49:54
【问题描述】:
javascript是否可以根据用户当前位置生成随机纬度和经度?我想在用户被定位到在传单地图上放置一些标记之后生成一些随机的纬度和经度位置。
【问题讨论】:
标签: javascript geolocation leaflet
javascript是否可以根据用户当前位置生成随机纬度和经度?我想在用户被定位到在传单地图上放置一些标记之后生成一些随机的纬度和经度位置。
【问题讨论】:
标签: javascript geolocation leaflet
可以,代码如下:
var latBounds = [-122, -77];
var lngBounds = [30, 50];
var features = [];
for( var i=0; i<80000; i++ ){
var lat = Math.random() * (latBounds[1]- latBounds[0] + 1) + latBounds[0];
var lng = Math.random() * (lngBounds[1]- lngBounds[0] + 1) + lngBounds[0];
features.push({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lat, lng]
},
"properties": {
"title": "point_" +i,
"marker-symbol": "harbor"
}
});
}
var geoJSON = {
"type": "FeatureCollection",
"features": features
};
【讨论】:
80000 来增加计数?