How to add a random point inside a polygon in Google Maps?
I have a bounds to a place and created a polygon of that place. How can I generate a random point inside the bounds of that polygon? One way of doing it. This will calculate the bounds of the polygon, then guess a random point inside that bounds, if the point is contained by the polygon, it will put a marker there. // calculate the bounds of the polygon var bounds = new google.maps.LatLngBounds(); for (var i=0; i < polygon.getPath().getLength(); i++) { bounds.extend(polygon.getPath().getAt(i)); } var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); // Guess 100 random points inside