mardi 10 mars 2020

Javascript random number between coordinates

I would like to generate points between the following coordinates : 52.1462 ,5.8676 - 52.1536 ,5.8376 This is where my rectangle is drawn.

I got the following code to randomize points between this rectangle:

var x_min = rectangle.getBounds().getEast();
var x_max = rectangle.getBounds().getWest();
var y_min = rectangle.getBounds().getSouth();
var y_max = rectangle.getBounds().getNorth();


var lat = y_min + (Math.random() * (y_max - y_min));
var lng = x_min + (Math.random() * (x_max - x_min));


lngBrd.push([l , b ]); == My starting point. 
lngBrd.push([lng, lat]); == should be random inside the box
lngBrd.push([lng, lat]); == should be random inside the box

But it gives me coordinates outside to box, see the img.

enter image description here

Where goes this wrong?




Aucun commentaire:

Enregistrer un commentaire