Reputation: 41
I recently tried the geocoder sample presented by Mapbox here for Android. It works well but it gives me only the American cities in my research even when using reverse geocoding. For example, when I click France in map the result is "not found". It works only for USA. So there is a way to get the geocoder service in other countries besides USA? France for example?
Upvotes: 4
Views: 1194
Reputation: 126
Is there a particular reason why you want to use the Geocoder provided by MapBox over the one provided by Android?
If you really want to use the Geocoder from MapBox you can always contact them and ask a technical question. They usually respond in one or two work days or faster depending on your time zone.
If not than you might want to consider using the android one instead.
Geocode
A class for handling geocoding and reverse geocoding. Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address.
Here is a code snippet that I use to transform a string into a list of Addresses:
public class Foo extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState){
if(Geocoder.isPresent()){
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName("Amsterdam", 10);
}
}
}
While writing the test code I noticed that the maxResults parameter is not functioning properly right now. The response from the function will only return one result in most situations. I still decided to post this as an answer since this bug will most likely be fixed someday. And for now it does allow you to search for addresses outside the US.
Upvotes: 2
Reputation: 3168
Mapbox has recently deprecated the library you are using in favor of Mapbox Android Services. It includes the geocoder your trying to implement with the added bonus of being updated in the future as new features are added.
Could you post how your setting up your client? here's a snippet of code I've used:
private void executeSearch(String query){
MapboxGeocoder client = new MapboxGeocoder.Builder()
.setAccessToken(getString(R.string.accessToken))
.setLocation(query)
.build();
client.enqueue(new Callback<GeocoderResponse>() {
@Override
public void onResponse(Response<GeocoderResponse> response, Retrofit retrofit) {
List<GeocoderFeature> results = response.body().getFeatures();
if (results.size() > 0) {
String placeName = results.get(0).getPlaceName();
Double placeLat = results.get(0).getLatitude();
Double placeLon = results.get(0).getLongitude();
Intent returnIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putDouble("placeLat", placeLat);
bundle.putDouble("placeLon", placeLon);
bundle.putString("placeName", placeName);
returnIntent.putExtra("result", bundle);
setResult(Activity.RESULT_OK, returnIntent);
finish();
} else {
Toast.makeText(SearchActivity.this, "No Results", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Throwable t) {
Log.e(LOG_TAG, "Error: ", t);
}
});
}// End executeSearch
Upvotes: 0