javascript是否可以根据用户当前位置生成随机纬度和经度?在用户定位到在传单地图上放置一些标记之后,我想生成一些随机的纬度和经度位置。
1 回答
1
是的,您可以,代码如下:
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
};
于 2020-09-17T18:52:42.023 回答