Skip to content

Web API Geo Location

Timothy Duffy edited this page Jun 5, 2013 · 4 revisions

Geo Location API's

The Geo Location API returns simple JSON object which can be used with mapping tools such as [Google maps] (https://developers.google.com/maps/documentation/javascript/tutorial) or [leafletjs] (http://leafletjs.com/).

Daily Geo Data Data

API URL

Parameters

Description

  • This API call returns all of the incidents for a single data that have geo location data decoded for them. Note: not all incidents will have geo data. If an incident does not have geo data, it is not returned in this call.

Headers in JSON

  • itemid- The unique Monroe County Incident ID
  • incident - The incident name that occurred at this address.
  • fulladdress - This is the full address of the incident as returned by Google.
  • lat - Latitiude value
  • lng - Longitude value

Response Object:

[
{
	"itemid":"MCOP131560164",
	"incident":"Hit and Run, no injury and no blocking",
	"fulladdress":"652 Rush West Rush Road, Rush, NY 14543, USA",
	"lat":"42.982689",
	"lng":"-77.6681849"
},
{
	"itemid":"CTYP131560126",
	"incident":"Parking complaint",
	"fulladdress":"151 Saint Paul Street, Baltimore, MD 21218, USA",
	"lat":"39.3313814",
	"lng":"-76.6161493"
}

... etc.

]

Google Maps Example Implementation

Below is a very simple example of how to use the above described API within Google Maps.

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<div id="map" style="margin: auto; width: 640px; height: 480px;"></div>

<script type="text/javascript">

	var map = new google.maps.Map(document.getElementById('map'), {
		zoom: 10,
		center: new google.maps.LatLng(43.1547, -77.6158),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});

	function loadData()
	{
		// get all of the incidents for today
		var url = "http://mcsafetyfeed.org/api/getgeo.php";
		$.getJSON(url, function (response) {handleData(response)});
	}

	function handleData(response)
	{
		// for each incident, place a marker on the map
		var n;
		for(n=0; n<response.length; n++)
		{
			lat = response[n].lat;
			lng = response[n].lng;
			event = response[n].event;
			var myLatLng = new google.maps.LatLng(lat,lng);
			var marker = new google.maps.Marker({
				position: myLatLng,
				//shadow: shadow,
				//icon:image,
				map: map,
				title: event,
				zIndex: 1
			});
		}   
	}

	// load the markers on the map
	loadData();

</script>

The above code example will produce a google map object that is center on the screen and is 640x480 pixels large. It will hold all of the incidents of the current day on it.

Clone this wiki locally