Q:

Geocoding addresses to geographic coordinates

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.

A:

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.

