Hack 18. Examine Patterns of Criminal Activity

Augment your local government's crime reports with Google Maps.

Chicagocrime.org (http://www.chicagocrime.org/), one of the original Google Maps hacks, is a freely browsable database of crimes reported in Chicago. It combines data that was screen scraped from the Chicago Police Department's Web site ( with Google Maps, enabling many new ways for Chicago residents to keep tabs on their neighborhoods and explore crimes reported throughout their city. The site lets you browse crime reports in many ways: crime type, street name, date, police district/beat, ZIP Code, city ward, and generic "location" (e.g., bowling alley, bar, gas station). Figure 3-3 shows a rash of peeping toms around residential Chicago, while Figure 3-4 shows the locations for bogus check reports. There's also a City map page at http://www.chicagocrime.org/map/ that lets you combine search criteria.

Figure 3-3. The most recent reports of illegal surveillance activity in Chicago

Figure 3-4. The most likely places to find bogus checks in Chicago

I developed Chicagocrime.org over a month's worth of nights and weekends in April 2005. Having gotten excited by the recently launched (at that time) Google Maps site, I spent a few evenings digging around Google's JavaScript and trying to embed custom maps into my own pages. After some hacking, I was able to display a custom map successfully. With my hacked-together map framework in place, it was just a matter of screen scraping the CPD's web site, geocoding each crime, and displaying the data. After Google released its official API at the end of June 2005, I updated Chicagocrime.org to make use of it.

3.3.1. Adding Ward and ZIP Code Boundaries

Aside from displaying a custom Google Map with relevant crime data on almost every page, Chicagocrime.org uses the Google Maps API in a couple of innovative ways. One way of navigating crime data is by police district. Because some residents of Chicago may not know their assigned districts, I created a "Find your beat and district" featurehttp://www.chicagocrime.org/districts/that helps people figure out which police beat and district they live in. It's simple to use: just pan and zoom the map to center it on a location, then click "Guess district."

It's simple under the hood, too. When a user clicks "Guess district," a bit of JavaScript calculates the center longitude and latitude of the current map view and sends that through a JavaScript XMLHttpRequest to a server-side script. The server code, written in Python and Django (http://www.djangoproject.com), uses a spatial query against PostGIS, a set of spatial extensions to PostgreSQL, to determine which district contains the given point. Finally, it passes the answer back to the site's JavaScript in your browser.

You can find out more about PostGIS at http://postgis.refractions.net/. O'Reilly's Web Mapping Illustrated offers a good tutorial on PostGIS, as well.

Similarly, Chicagocrime.org lets you navigate crimes by city ward, and there's a "Find your ward" feature on the ward page: http://www.chicagocrime.org/wards/. For ward and ZIP Code pages, chicagocrime.org uses the Google Maps polyline-drawing API to draw the border for the given ward or ZIP Code on the map. I did this by obtaining the ward and ZIP Code boundaries in ESRI Shapefile format from the City of Chicago's GIS department at http://www.cityofchicago.org/gis/. I loaded the shapefiles into a PostgreSQL database and converted the data into longitude-latitude coordinates using the conversion functions in PostGIS. Finally, it was just a matter of feeding the points into the Google Maps polyline-drawing API, and voila: we have ward and ZIP Code borders.

3.3.2. See Also

  • Rendering arbitrary GIS vector data on Google Maps is an interesting and still evolving subject. "How Big Is That, Exactly?" [Hack #28] involves rendering vector data from GIS sources on top of Google Maps.

Adrian Holovaty

You Are Here: Introducing Google Maps

Introducing the Google Maps API

Mashing Up Google Maps

On the Road with Google Maps

Google Maps in Words and Pictures

API Tips and Tricks

Extreme Google Maps Hacks

Google Maps Hacks
Google Maps Hacks: Tips & Tools for Geographic Searching and Remixing
ISBN: 0596101619
EAN: 2147483647
Year: N/A
Pages: 131

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net