MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Reverse Geocoding code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100374] Reverse Geocoding code
  • From: "Coleman, Mark" <Mark.Coleman at LibertyMutual.com>
  • Date: Tue, 2 Jun 2009 06:43:19 -0400 (EDT)

Greetings,

Periodically I use Mathematica to help with geospatial analysis. Recently,
Google Maps added the ability to reverse geocode an address, that is,
translate a human readable street address into the corresponding
lat-long coordinates (within a reasonable degree of specificity). Here
is some Mathematica code to do this:


 reverseGeoCode[{lat_,long_},outputType_]:=
Module[{apiKey,baseURL,qAddress,qAddressFinal,finalURL,geoRes},
   apiKey="PUT YOUR KEY HERE";
   baseURL="http://maps.google.com/maps/geo?";;
   qAddressFinal=StringJoin[ToString[lat],",",ToString[long]];

finalURL=baseURL<>"q="<>qAddressFinal<>"&output="<>outputType<>"&"<=
>"key
="<>apiKey;
   geoRes=ToExpression["{"<>Import[finalURL]<>"}"];
   geoRes
  
   ];

This essentially involves converting the lat-long code to a string, then
composing the appropriate URL to invoke the Google web service. This is
trivial in Mathematica (I'm running v7) and, in my experience, a great way to
highlight the power of Mathematica to my business colleages (when I'm not
rotating a 3-d graphic for them!)

Please note that in order to run this code, you need to have a
Google-issued API Key (I've removed my key from the above code -- just
replace it with yours). The keys are free and give you access to
Google's online web services. I've found that performance is generally
pretty good, thought Google does place a limit on how many times you can
call this service during a 24 hour period (the number is around 5000 per
IP Address). So if you have a large number of addresses to reverse
geocode, this may not be the most efficient way to do so. Also, this
works quite well for U.S. lat-long coordinates. I have not tested it for
other countries.

As an example:

In[72]:= computeLatLong[{"100 Trade Center Drive", "Champaign", "IL"
,"61820-7237"}, "csv"]

Out[72]= {200, 8, 40.0971, -88.2456}



For information the Google Maps API, please see:
http://code.google.com/more/#products-geo-maps


Cheers!


Mark S. Coleman
Claims Research & Development

Personal Market Claims
Mark.Coleman at libertymutual.com
Boston: (617) 654-4572  SDN: 8-654-4572
Portsmouth: (603) 245-5003
NOTICE: The information contained in this electronic mail transmission
is intended by Liberty Mutual for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential. If you have received this
electronic mail transmission in error, please delete it from your system
without copying or forwarding it, and notify the sender of the error by
reply e-mail or by telephone (collect), so that the sender's address
records can be corrected.





  • Prev by Date: Re: Re: How can I get the previous Fibonacci calculated
  • Next by Date: Re: matching misspelled names
  • Previous by thread: Re: Speeding up code
  • Next by thread: Re: 100,000 posts!