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;

var map;
var messagediv=document.getElementById('messagediv');
var tileProviderURL="";
var tileProviderAttribution='&copy; <a href="//">OpenStreetMap</a> contributors';

var mapDivID = "map_canvas";
var latlng=[54.6228,-5.8955];
var zoom = 12;

var routePoints=new Array(0);

function initialize()
	document.getElementById(mapDivID).style.cursor = "crosshair";
	map =,{
		fullscreenControl: true,
  		fullscreenControlOptions: {
    		position: 'topleft'
	}).setView(latlng, zoom);
	L.tileLayer('{id}/{z}/{x}/{y}.png?', {
		maxZoom: 18,
		attribution: 'Map data &copy; <a href="//">OpenStreetMap</a> contributors, ' +
			'<a href="//">CC-BY-SA</a>', 
		id: 'mapbox.streets'
	var openstreetmap = L.tileLayer('https://{s}.'+tileProviderURL+'/{z}/{x}/{y}.png', {
		maxZoom: 18,
		attribution: tileProviderAttribution

function ftn_button_clicked()
	var num=document.getElementById("nm").value;
	if (num<1000)

function ftn_button_clearmap()

function clearmarkers()
	if (arrMarkers) 
		for (i in arrMarkers) 
	arrMarkers=new Array(0);

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 = [ + 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 marker = L.marker(location,{title:text});
    return marker;

Relevant Links

Leaftlet Maps

Version History

  • Version 4 - 5th December 2019 - Convert to Leaftlet Maps
  • Version 3 - 14th March 2014 - When you hover over a marker it now displays the location latitude and longitude
  • Version 2 - 9th November 2013 - Clean up code
  • Version 1 - 20th November 2010 - Initial version

Comments For This Page

It'd be nice to have a clear marker button.
On 30th November 2019
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: