7
$\begingroup$

I am writing a research proposal for a project on voter turnout as related to proximity to mass transit. The first part of my project would require geocoding hundreds of thousands of addresses, but I'd rather not have my laptop running ArcGIS for days on end to do it. My school's supercomputer does not have GIS software but it does have Mathematica Version 8. Is there a way to geocode addresses in Mathematica? I've found several workaround solutions online, but nothing that I think would get the approval of the campus IT office.

$\endgroup$
4
  • $\begingroup$ That data should exists already, try contacting local government or buy it from some map company like google maps $\endgroup$
    – ssch
    Feb 4, 2013 at 21:51
  • 4
    $\begingroup$ You can use Mathematica to implement any Web-based method described on the GIS site. For instance, about 20 months ago I searched that site for solutions and implemented two of them in MMA--Google Maps and Yahoo Maps. These are contractually limited to a few thousand per day (which was good enough for me), but there are others with fewer limitations. The GIS community can also provide advice on commercial solutions. $\endgroup$
    – whuber
    Feb 4, 2013 at 22:44
  • 2
    $\begingroup$ This exists within Wolfram Language now: FindGeoLocation. $\endgroup$
    – Carl Lange
    Feb 2, 2020 at 17:11
  • $\begingroup$ Thanks @CarlLange! $\endgroup$ Feb 10, 2020 at 15:57

1 Answer 1

10
$\begingroup$

Now Google needs a key for the API. Here is my updated function:

geocoder[address_String] := 
Module[{data, url, results, key = "your_google_api_key"}, 
    url = "https://maps.googleapis.com/maps/api/geocode/json?address="<>URLEncode[address]<>"&sensor=false&key="<>key;
    data = Import[url,"RawJSON"];
    If[data[["status"]] =!= "OK", data];

    results = Association/@Transpose@{
         Thread["location_type"-> data[["results", All,"geometry",  "location_type"]]]
        ,Thread["formatted_address"-> data[["results", All, "formatted_address"]]]
        ,Thread["latlon"-> Values@data[["results", All, "geometry", "location"]]]
    };

    <|
     "status" -> data[["status"]]
    ,"address_quantity" -> Length@data[["results"]]
    , "results" -> results
    , "results_original" -> data["results"]
    |>
]

After replace your API key in the code above, you can test it like:

geocoder["Av Paulista, 1578, Sao Paulo, Brasil"]["results"]

you get the right coordinates:

     {<|
      "location_type" -> "ROOFTOP"
      ,"formatted_address" -> "Av. Paulista, 1578 - Bela Vista, São Paulo - SP, 01310-200, Brazil"
      , "latlon" -> {-23.5615, -46.656}|
     |>}

Here is the Google Documentation about geocoding, and how to get your API key.

$\endgroup$
2
  • 1
    $\begingroup$ You can try other geocoding API: 7 Free Geocoding APIs: Google, Bing, Yahoo and MapQuest, APIs are very similar $\endgroup$
    – Tuku
    Feb 5, 2013 at 15:51
  • 1
    $\begingroup$ I implemented your geocoder into my init.m file and it worked for awhile but now I get the following error message: " Import::noelem: The Import element "1" is not present when importing as JSON. " What has changed? $\endgroup$
    – user43188
    Oct 21, 2018 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.