is possible generate random latitude , longitude google maps api , center on coordinates (i need coordinates somewhere on continental part of usa)?
first of need define bounds of continental usa. can webpage http://econym.org.uk/gmap/states.xml. 1 have them can use data structure populate , can store them in variable in get variable. , use following code generate random coordinates
var bounds = yourarray.getbounds(); map.fitbounds(bounds); var sw = bounds.getsouthwest(); var ne = bounds.getnortheast(); (var = 0; < 100; i++) { var ptlat = math.random() * (ne.lat() - sw.lat()) + sw.lat(); var ptlng = math.random() * (ne.lng() - sw.lng()) + sw.lng(); var point = new google.maps.latlng(ptlat, ptlng); if (google.maps.geometry.spherical.computedistancebetween(point, circle.getcenter()) < circle.getradius()) { createmarker(map, point, "marker " + i); here function create marker
function createmarker(map, point, content) { var marker = new google.maps.marker({ position: point, map: map }); google.maps.event.addlistener(marker, "click", function(evt) { infowindow.setcontent(content + "<br>" + marker.getposition().tourlvalue(6)); infowindow.open(map, marker); }); return marker; } google.maps.event.adddomlistener(window, 'load', initialize); finally call fitbounds(marker) center , zoom marker on generated marker.
Comments
Post a Comment