Plot Random Markers

Number of markers to plot:

A maximum of 999 markers can be plotted.

How it Works

var map;
var arrMarkers=new Array(0);
var bounds;

function initialize()
var latlng = new google.maps.LatLng(54.62279178711505,-5.895538330078125);
var myOptions = {zoom:12,center:latlng,mapTypeId:google.maps.MapTypeId.HYBRID,mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU}};
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

function ftn_button_clicked()
if (arrMarkers)
for (i in arrMarkers)
arrMarkers=new Array(0);
var num=document.getElementById("nm").value;
if (num<1000)

function plotrandom(number)
bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = -;

for(var i=0;i<number;++i)
var point = new google.maps.LatLng( + latSpan * Math.random(),southWest.lng() + lngSpan * Math.random());
for(var i=0;i<number;++i)
var str_text=i+" : "+pointsrand[i];
var marker=placeMarker(pointsrand[i],str_text);

function placeMarker(location,text)
var iconFile = '';
var marker = new google.maps.Marker({position:location,map:map,icon:iconFile,title:text.toString(),draggable:false});
return marker;

Relevant Links

Google Maps API

Version History

  • Version 3 (14/03/2014) - When you hover over a marker it now displays the location latitude and longitude
  • Version 2 (09/11/2013) - Clean up code
  • Version 1 (20/11/2010) - Initial version

Comments For This Page

On 11th March 2016
Hi, the markers now display the location latitude and longitude. In terms of restricting the area, this is not possible.
By Daft Logic on 14th March 2015
How do you get the exact coordinates of a randomly generated point? And is there any way to restrict this to a set area (say, to not place any points in the ocean)?
On 6th March 2015
Doesn't work
On 3rd October 2011
i find this VERY usefull.

Means i can plot GPS stuff
By Mapping stuff on 5th November 2009
i dont think there is a point!!!
By a person on 23rd September 2008
what is the point of this example?!?
By BoyHowdy on 23rd September 2008
with broadband speeds ever increasing the number of pointless plots should be increased to the three digit mark at least!
By physco219 on 1st January 2008

Add your own comment below and let others know what you think:

Share This Page

Share this page with others using one of the methods below. Telling others about Daft Logic is good and we appreciate your support!