Google Maps Meets Swansea PD 2

I've made a few updates to the Swansea, MA Police Dispatch Log page.

  • The date range for the incidents in the database is now displayed.
  • The number of incidents to display on the map at one time is now adjustable. This can be adjusted based on the performance of your machine.
  • The incident and date are listed in the marker list links
  • The database was populated back through January 2009. 
I did receive questions as to how often the database is updated. The database is updated shortly after the Swansea Police Department Dispatch Log is update on the Swansea Police Department website.



   

C# URL Shortening with Bit.ly

With the popularity of social network sites that limit the number of characters a user can enter in post, URL shortening has become a popular business.  There are many sites are available that will return a "shortened" URL for a user entered "long" URL.  Theoretically, the shortened URL contains  less characters and makes it easier to share a URL where character count is limited.  For example, the long URL http://www.bpsoftware.com/blog/2010/02/google-maps-meets-swansea-pd.aspx when shortened, via Bit.ly, becomes http://bit.ly/btc1sF.

As with many popular service websites, Bit.ly has an API which allows you to programmatically shorten a URL.  After you create your bit.ly account you can use the following code to returned a shortened URL within your application. You can see the code in use on sites like F-theman.com.

private static string GetShortUrl( string longUrl )
    {
        string login = "yourlogin";
        string apiKey = "yourapikey";

        string url = string.Format ( "http://api.bit.ly/shorten?format=xml&version=2.0.1&longUrl={0}&login={1}&apiKey={2}",
                          HttpUtility.UrlEncode ( longUrl ), login, apiKey );
        try
        {
            System.Net.WebClient we = new System.Net.WebClient ();
            string ret = we.DownloadString ( url );
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
            doc.LoadXml ( ret );

            System.Xml.XmlNode xnode = doc.DocumentElement.SelectSingleNode ( "results/nodeKeyVal/shortUrl" );
            if ( !System.String.IsNullOrEmpty ( xnode.InnerText ) )
            {
                return xnode.InnerText;
            }

            else
            {
                throw new Exception ( "Unable to shorten URL" );
            }
        }
        catch ( Exception )
        {
            throw;
        }
    }



   

Google Maps meets Swansea PD

Anyone that knows me knows that while I am sitting at my desk clicking away on the keyboard I am also listening to the Police Scanner.  I have been listening to a Police Scanner for as long as I can remember. One of the departments I have programmed into the scanner is the Swansea Police Department.  The Swansea Police Department also posts their Police Dispatch Log on their website (You can view my version Swansea Police Dispatch Log here).

In preparation for a future project, the other day I decided to start dabbling with the Google Maps API.  APIs allow developers to easily integrate functionality from other applications/services into their application.  The Google Maps API offers a wide range of map/location features.

As I was listening to the scanner I thought it'd be a great idea to see where the Swansea Police have been dispatched over a period of time on a map.  Seeing the locations on a map clearly displays the more active areas.  The concept was simple, but the question was on how I was going to get all of the incidents into a database for display in a map.  With the Swansea Police Department having their Dispatch Log online, the question was easily answered. The answer is...

The format of the incidents on the police log is a pretty standard format, so I wrote a program that uses RegularExpressions to parse out the Date, Time, Reason and Location of the dispatch incidents.  Each incident is then stored in a SQL Database.  After the page is parsed, I then determine the longitude and latitude location for each incident by GeoCoding the address using the Google Maps API.  I store the status, accuracy value, longitude and latitude of the address in the database.   I then created a page that reads the database (for a filtered set of incidents) and display markers on a map for each incident. Only incidents that have been successfully geocoded are displayed. If you click on a marker you can see the date, time, reason and location of the incident.  You can also click on an incident link to see where it is located on the map.

View my version Swansea Police Dispatch Log here.

I have a few other enhancements I am planning on adding to the map in the future. Check it out!

I know, I know, I am often told 'I am such a geek...'