Generate Random Latitude And Longitude With Javascript After Geolocation
Is it possible with javascript to generate random latitude and longitude based on the user current position? I want to generate some random latitude and longitude positions after t
Solution 1:
Yes you can, Code below:
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
};
Post a Comment for "Generate Random Latitude And Longitude With Javascript After Geolocation"