Skip to content

Instantly share code, notes, and snippets.

@adam-davis
Created July 29, 2012 18:59
Show Gist options
  • Save adam-davis/3201144 to your computer and use it in GitHub Desktop.
Save adam-davis/3201144 to your computer and use it in GitHub Desktop.
Geocoding in Android
Geocoder geocoder = new Geocoder(digitalGraffiti,Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocationName(input.getText().toString(), MAX_GEOCODER_RESULT);
} catch (IOException e) {
e.printStackTrace();
}
//If we have results display the dialog window allowing the user to view / select the,
if (addresses.size() != 0)
displayAddressDialogWindow(addresses);
//Method Added to Nicholas Smith's Yelp classes for GSON
class Business{
....
....
public Address toAddress()
{
//Initializing to english local - assuming US only
//but this is a good spot to look into Internationalization
Address address = new Address(new Locale("en"));
address.setFeatureName(this.getName());
address.setLocality(this.location.getCity());
address.setAdminArea(this.location.getStateCode());
address.setCountryCode(this.location.getCountryCode());
address.setLatitude(this.location.getCoordinate().getLatitude());
address.setLongitude(this.location.getCoordinate().getLongitude());
address.setFeatureName(this.name);
return address;
}
//Searching for location Name using geocoder...
Geocoder geocoder = new Geocoder(digitalGraffiti,Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocationName(input.getText().toString(), MAX_GEOCODER_RESULT);
} catch (IOException e) {
e.printStackTrace();
}
/* Querying Yelp for business names since google
* might not catch the search terms
*/
Yelp yelp = new Yelp();
YelpSearchResult yelpSearchResult = yelp.search(input.getText().toString(), digitalGraffiti.getLatitude(), digitalGraffiti.getLongitude());
//Adding the results to our address list
for(Business biz : yelpSearchResult.getBusinesses())
{
addresses.add(biz.toAddress());
}
//And then displaying them - no need to change any code is our display dialog window method
if (addresses.size() != 0)
displayAddressDialogWindow(addresses);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment