Skip to content

Instantly share code, notes, and snippets.

@leebyron
Created October 14, 2014 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leebyron/d345139475f899efe572 to your computer and use it in GitHub Desktop.
Save leebyron/d345139475f899efe572 to your computer and use it in GitHub Desktop.
Simple geocoder
class Geocoder{
// google maps api key
String apiKey;
Geocoder(String apiKey){
this.apiKey = apiKey;
}
double[] locate(String location){
String search = URLEncoder.encode(location);
String url = "http://maps.google.com/maps/geo?q="+search+"&output=csv&key="+apiKey;
String[] answer = loadStrings(url);
String[] values = split(answer[0], ',');
double latitude = Double.parseDouble(values[2]);
double longitude = Double.parseDouble(values[3]);
double[] coordinates = {latitude, longitude};
return coordinates;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment