Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
autocomplete = (GeocoderAutoCompleteView) findViewById(R.id.query);
autocomplete.setAccessToken(Utils.getMapboxAccessToken(this));
autocomplete.setType(GeocodingCriteria.TYPE_POI);
autocomplete.setLimit(10);
autocomplete.setOnFeatureListener(new GeocoderAutoCompleteView.OnFeatureListener() {
@Override
public void OnFeatureClick(CarmenFeature feature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public class GeocoderAdapter extends BaseAdapter implements Filterable {
private final Context context;
private String accessToken;
private String country;
private String[] countries;
private String type;
private double[] bbox;
private Position position;
private int limit;

private GeocoderFilter geocoderFilter;

Expand Down Expand Up @@ -83,17 +85,40 @@ public String getCountry() {
}

/**
* Parameter limits results to a set of one or more countries, specified with
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes
* and separated by commas.
* Parameter limits results to a country. Use one of the
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes. The country code is
* case sensitive and needs to be all lowercase.
*
* @param country String matching country code.
* @param country String matching country code. Needs to be lowercase.
* @since 1.3.0
*/
public void setCountry(String country) {
this.country = country;
}

/**
* Get the countries you are limiting your geocoding results if applicable.
*
* @return a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a>
* country code inside a String array.
* @since 2.0.0
*/
public String[] getCountries() {
return countries;
}

/**
* Parameter limits results to a set of one or more countries. Use one or more of the
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes,
* separated by commas inside a String array. The country codes are case sensitive and needs to be all lowercase.
*
* @param countries String array containing the country codes you want to limit results to.
* @since 2.0.0
*/
public void setCountries(String[] countries) {
this.countries = countries;
}

/**
* Get the geocoder filter type.
*
Expand Down Expand Up @@ -180,6 +205,26 @@ public void setProximity(Position position) {
this.position = position;
}

/**
* Returns integer number representing the amount of results
*
* @return integer value
* @since 2.0.0
*/
public int getLimit() {
return limit;
}

/**
* Limit the number of results returned. The default is 5.
*
* @param limit the integer value representing the amount of results desired.
* @since 2.0.0
*/
public void setLimit(int limit) {
this.limit = limit;
}

/*
* Required by BaseAdapter
*/
Expand Down Expand Up @@ -305,6 +350,9 @@ protected FilterResults performFiltering(CharSequence constraint) {
if (getCountry() != null) {
builder.setCountry(getCountry());
}
if (getCountries() != null) {
builder.setCountries(getCountries());
}
if (getProximity() != null) {
builder.setProximity(getProximity());
}
Expand All @@ -314,6 +362,9 @@ protected FilterResults performFiltering(CharSequence constraint) {
if (getBbox() != null) {
builder.setBbox(bbox[0], bbox[1], bbox[2], bbox[3]);
}
if (getLimit() != 0) {
builder.setLimit(limit);
}

// Do request
response = builder.build().executeCall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ public void setType(String type) {
adapter.setType(type);
}

/**
* Parameter limits results to a country. Use one of the
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes. The country code is
* case sensitive and needs to be all lowercase.
*
* @param country String matching country code. Needs to be lowercase.
* @since 2.0.0
*/
public void setCountry(String country) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to offer a varargs method here for convenience so that the comma separated format is abstracted:

public void setCountries(String... countries)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point @ivovandongen, adding.

adapter.setCountry(country);
}

/**
* Parameter limits results to a set of one or more countries. Use one or more of the
* <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166 alpha 2</a> country codes,
* separated by commas inside a String array. The country codes are case sensitive and needs to be all lowercase.
*
* @param countries String array containing the country codes you want to limit results to.
* @since 2.0.0
*/
public void setCountries(String[] countries) {
adapter.setCountries(countries);
}

/**
* Bounding box within which to limit results.
*
Expand Down Expand Up @@ -143,6 +167,16 @@ public void setProximity(Position position) {
adapter.setProximity(position);
}

/**
* Limit the number of results returned. The default is 5.
*
* @param limit the integer value representing the amount of results desired.
* @since 2.0.0
*/
public void setLimit(int limit) {
adapter.setLimit(limit);
}

/**
* Sets the listener that will be notified when the user clicks an item in the drop down list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface GeocodingService {
* @param types Filter results by one or more type.
* @param autocomplete True if you want auto complete.
* @param bbox Optionally pass in a bounding box to limit results in.
* @param limit Optionally pass in a limit the amount of returning results.
* @return A retrofit Call object
* @since 1.0.0
*/
Expand All @@ -41,5 +42,6 @@ Call<GeocodingResponse> getCall(
@Query("proximity") String proximity,
@Query("types") String types,
@Query("autocomplete") Boolean autocomplete,
@Query("bbox") String bbox);
@Query("bbox") String bbox,
@Query("limit") String limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public Call<GeocodingResponse> getCall() {
builder.getProximity(),
builder.getGeocodingTypes(),
builder.getAutocomplete(),
builder.getBbox());
builder.getBbox(),
builder.getLimit());

return call;
}
Expand Down Expand Up @@ -170,6 +171,7 @@ public static class Builder extends MapboxBuilder {
private String geocodingTypes = null;
private Boolean autocomplete = null;
private String bbox = null;
private String limit = null;

/**
* Constructor
Expand Down Expand Up @@ -347,6 +349,22 @@ public Builder setBbox(double minX, double minY, double maxX, double maxY) throw
return this;
}

/**
* Limit the number of results returned. The default is 5 for forward geocoding and 1 for
* reverse geocoding.
*
* @param limit the integer value representing the amount of results desired.
* @return Builder
* @since 2.0.0
*/
public Builder setLimit(int limit) {
if (limit == 0) {
return this;
}
this.limit = String.format(Locale.US, "%d", limit);
return this;
}

/**
* @return your Mapbox access token.
* @since 1.0.0
Expand Down Expand Up @@ -417,6 +435,14 @@ public String getBbox() {
return bbox;
}

/**
* @return the integer value representing the amount of results desired.
* @since 2.0.0
*/
public String getLimit() {
return limit;
}

public Builder setClientAppName(String appName) {
super.clientAppName = appName;
return this;
Expand Down