-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
525276f
commit 63ab3cf
Showing
61 changed files
with
4,231 additions
and
1,315 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
samples/src/main/java/com/mapbox/samples/BasicV6BatchGeocoding.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.mapbox.samples; | ||
|
||
import com.mapbox.api.geocoding.v6.MapboxV6BatchGeocoding; | ||
import com.mapbox.api.geocoding.v6.V6RequestOptions; | ||
import com.mapbox.api.geocoding.v6.V6StructuredInputQuery; | ||
import com.mapbox.api.geocoding.v6.V6ForwardGeocodingRequestOptions; | ||
import com.mapbox.api.geocoding.v6.models.V6BatchResponse; | ||
import com.mapbox.api.geocoding.v6.models.V6Feature; | ||
import com.mapbox.api.geocoding.v6.models.V6FeatureType; | ||
import com.mapbox.api.geocoding.v6.models.V6Response; | ||
import com.mapbox.api.geocoding.v6.V6ReverseGeocodingRequestOptions; | ||
import com.mapbox.geojson.BoundingBox; | ||
import com.mapbox.geojson.Point; | ||
import com.mapbox.sample.BuildConfig; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class BasicV6BatchGeocoding { | ||
|
||
private static List<V6RequestOptions> requestOptions() { | ||
final V6ForwardGeocodingRequestOptions forwardOptions = V6ForwardGeocodingRequestOptions | ||
.builder("1600 Pennsylvania Avenue NW, Washington, DC 20500, United States") | ||
.types(V6FeatureType.ADDRESS) | ||
.limit(1) | ||
.boundingBox(BoundingBox.fromLngLats(-80, 35, -70, 40)) | ||
.build(); | ||
|
||
final V6StructuredInputQuery structuredInputQuery = V6StructuredInputQuery.builder() | ||
.addressNumber("1600") | ||
.street("Pennsylvania Avenue NW") | ||
.postcode("20500") | ||
.place("Washington, DC") | ||
.build(); | ||
|
||
final V6ForwardGeocodingRequestOptions structuredInputOptions = V6ForwardGeocodingRequestOptions | ||
.builder(structuredInputQuery) | ||
.country("us") | ||
.build(); | ||
|
||
final V6ReverseGeocodingRequestOptions reverseOptions = V6ReverseGeocodingRequestOptions | ||
.builder(Point.fromLngLat(-73.986136, 40.748895)) | ||
.types(V6FeatureType.ADDRESS) | ||
.build(); | ||
|
||
return Arrays.asList(forwardOptions, structuredInputOptions, reverseOptions); | ||
} | ||
|
||
public static void main(String[] args) { | ||
final MapboxV6BatchGeocoding geocoding = MapboxV6BatchGeocoding | ||
.builder( | ||
BuildConfig.MAPBOX_ACCESS_TOKEN, | ||
requestOptions() | ||
) | ||
.build(); | ||
|
||
geocoding.enqueueCall(new Callback<V6BatchResponse>() { | ||
@Override | ||
public void onResponse(Call<V6BatchResponse> call, Response<V6BatchResponse> response) { | ||
System.out.println("Response code: " + response.code()); | ||
System.out.println("Response message: " + response.message()); | ||
|
||
final V6BatchResponse body = response.body(); | ||
if (body == null) { | ||
System.out.println("Response body is null"); | ||
return; | ||
} | ||
|
||
System.out.println("Number of responses: " + body.responses().size()); | ||
|
||
for (V6Response v6Response : body.responses()) { | ||
System.out.println("Number of results: " + v6Response.features().size()); | ||
|
||
final String results = v6Response.features().stream() | ||
.map(V6Feature::toString) | ||
.collect(Collectors.joining(", \n")); | ||
|
||
System.out.println("Features: " + results); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<V6BatchResponse> call, Throwable t) { | ||
System.out.println(t); | ||
} | ||
}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
samples/src/main/java/com/mapbox/samples/BasicV6ForwardGeocoding.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mapbox.samples; | ||
|
||
import com.mapbox.api.geocoding.v6.MapboxV6Geocoding; | ||
import com.mapbox.api.geocoding.v6.V6ForwardGeocodingRequestOptions; | ||
import com.mapbox.api.geocoding.v6.models.V6Response; | ||
import com.mapbox.api.geocoding.v6.models.V6Feature; | ||
import com.mapbox.api.geocoding.v6.models.V6FeatureType; | ||
import com.mapbox.sample.BuildConfig; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class BasicV6ForwardGeocoding { | ||
|
||
public static void main(String[] args) { | ||
final V6ForwardGeocodingRequestOptions requestOptions = V6ForwardGeocodingRequestOptions | ||
.builder("740 15th St NW, Washington, DC 20005") | ||
.types(V6FeatureType.ADDRESS) | ||
.build(); | ||
|
||
final MapboxV6Geocoding geocoding = MapboxV6Geocoding | ||
.builder(BuildConfig.MAPBOX_ACCESS_TOKEN, requestOptions) | ||
.build(); | ||
|
||
geocoding.enqueueCall(new Callback<V6Response>() { | ||
@Override | ||
public void onResponse(Call<V6Response> call, Response<V6Response> response) { | ||
final V6Response body = response.body(); | ||
if (body == null) { | ||
System.out.println("Response body is null"); | ||
return; | ||
} | ||
|
||
System.out.println("Number of results: " + body.features().size()); | ||
|
||
final String results = body.features().stream() | ||
.map(V6Feature::toString) | ||
.collect(Collectors.joining(", \n")); | ||
|
||
System.out.println("Features: " + results); | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<V6Response> call, Throwable t) { | ||
System.out.println(t); | ||
} | ||
}); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
samples/src/main/java/com/mapbox/samples/BasicV6StructuredInputForwardGeocoding.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.mapbox.samples; | ||
|
||
import com.mapbox.api.geocoding.v6.V6StructuredInputQuery; | ||
import com.mapbox.api.geocoding.v6.MapboxV6Geocoding; | ||
import com.mapbox.api.geocoding.v6.V6ForwardGeocodingRequestOptions; | ||
import com.mapbox.api.geocoding.v6.models.V6Feature; | ||
import com.mapbox.api.geocoding.v6.models.V6FeatureType; | ||
import com.mapbox.api.geocoding.v6.models.V6Response; | ||
import com.mapbox.sample.BuildConfig; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Callback; | ||
import retrofit2.Response; | ||
|
||
public class BasicV6StructuredInputForwardGeocoding { | ||
|
||
public static void main(String[] args) { | ||
final V6StructuredInputQuery query = V6StructuredInputQuery.builder() | ||
.addressNumber("740") | ||
.street("15th St") | ||
.place("Washington") | ||
.postcode("20005") | ||
.build(); | ||
|
||
final V6ForwardGeocodingRequestOptions requestOptions = V6ForwardGeocodingRequestOptions | ||
.builder(query) | ||
.country("United States") | ||
.types(V6FeatureType.ADDRESS) | ||
.autocomplete(false) | ||
.build(); | ||
|
||
final MapboxV6Geocoding geocoding = MapboxV6Geocoding | ||
.builder(BuildConfig.MAPBOX_ACCESS_TOKEN, requestOptions) | ||
.build(); | ||
|
||
geocoding.enqueueCall(new Callback<V6Response>() { | ||
@Override | ||
public void onResponse(Call<V6Response> call, Response<V6Response> response) { | ||
final V6Response body = response.body(); | ||
if (body == null) { | ||
System.out.println("Response body is null"); | ||
return; | ||
} | ||
|
||
System.out.println("Number of results: " + body.features().size()); | ||
|
||
final String results = body.features().stream() | ||
.map(V6Feature::toString) | ||
.collect(Collectors.joining(", \n")); | ||
|
||
System.out.println("Features: " + results); | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<V6Response> call, Throwable t) { | ||
System.out.println(t); | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.