Created
July 29, 2012 18:59
-
-
Save adam-davis/3201144 to your computer and use it in GitHub Desktop.
Geocoding in Android
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
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); |
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
//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; | |
} |
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
//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