Created
October 14, 2014 21:50
-
-
Save leebyron/d345139475f899efe572 to your computer and use it in GitHub Desktop.
Simple geocoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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