From bc9b62990ed5331604682ba59165502453d3f04f Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Mon, 16 Sep 2019 23:50:26 +0300 Subject: [PATCH 1/6] [geocoding] Add intersection search support. --- .../api/geocoding/v5/MapboxGeocoding.java | 20 +++++++++++ .../api/geocoding/v5/GeocodingTestUtils.java | 3 ++ .../api/geocoding/v5/MapboxGeocodingTest.java | 35 ++++++++++++++----- .../test/resources/forward_intersection.json | 1 + 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 services-geocoding/src/test/resources/forward_intersection.json diff --git a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java index 2842c2a2f..d364d1508 100644 --- a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java +++ b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java @@ -247,6 +247,8 @@ public abstract static class Builder { private List countries = new ArrayList<>(); + private List intersectionStreets = new ArrayList<>(); + /** * Perform a reverse geocode on the provided {@link Point}. Only one point can be passed in as * the query and isn't guaranteed to return a result. If you are an enterprise customer and @@ -581,6 +583,20 @@ public abstract Builder reverseMode( abstract MapboxGeocoding autoBuild(); + + /** + * Specify the two street names for intersection search. + * + * @param streetOne First street name of the intersection + * @param streetTwo Second street name of the intersection + * @return this builder for chaining options together + */ + public Builder intersectionStreets(@NonNull String streetOne, @NonNull String streetTwo) { + intersectionStreets.add(streetOne); + intersectionStreets.add(streetTwo); + return this; + } + /** * Build a new {@link MapboxGeocoding} object. * @@ -593,6 +609,10 @@ public MapboxGeocoding build() { country(TextUtils.join(",", countries.toArray())); } + if (intersectionStreets.size() == 2) { + query(TextUtils.join(" and ", intersectionStreets.toArray())); + } + // Generate build so that we can check that values are valid. MapboxGeocoding geocoding = autoBuild(); diff --git a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/GeocodingTestUtils.java b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/GeocodingTestUtils.java index 2653b915e..a559426c4 100644 --- a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/GeocodingTestUtils.java +++ b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/GeocodingTestUtils.java @@ -20,6 +20,7 @@ public class GeocodingTestUtils extends TestUtils { private static final String FORWARD_INVALID = "forward_invalid.json"; private static final String FORWARD_VALID_ZH = "forward_valid_zh.json"; private static final String FORWARD_BATCH_GEOCODING = "geocoding_batch.json"; + private static final String FORWARD_INTERSECTION = "forward_intersection.json"; private MockWebServer server; protected HttpUrl mockUrl; @@ -43,6 +44,8 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio response = loadJsonFixture(FORWARD_GEOCODING); } else if (request.getPath().contains("sandy")) { response = loadJsonFixture(FORWARD_INVALID); + } else if (request.getPath().contains("%20and%20")) { + response = loadJsonFixture(FORWARD_INTERSECTION); } else { response = loadJsonFixture(FORWARD_VALID_ZH); } diff --git a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java index ad96436fb..a3fb0da4b 100644 --- a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java +++ b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java @@ -1,25 +1,16 @@ package com.mapbox.api.geocoding.v5; import com.mapbox.api.geocoding.v5.models.GeocodingResponse; -import com.mapbox.core.TestUtils; import com.mapbox.core.exceptions.ServicesException; import com.mapbox.geojson.BoundingBox; import com.mapbox.geojson.Point; -import org.hamcrest.junit.ExpectedException; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import java.io.IOException; import java.util.List; import java.util.Locale; -import okhttp3.HttpUrl; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; import retrofit2.Response; import static org.hamcrest.Matchers.startsWith; @@ -307,4 +298,30 @@ public void fuzzyMatch_getsAddedToUrlCorrectly() throws Exception { assertTrue(mapboxGeocoding.cloneCall().request().url().toString() .contains("fuzzyMatch=true")); } + + @Test + public void intersectionSearchSanity() throws IOException { + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .intersectionStreets("Market Street", "Fremont Street") + .proximity("-122.39738575285674,37.792514711136945") + .baseUrl(mockUrl.toString()) + .build(); + assertNotNull(mapboxGeocoding); + Response response = mapboxGeocoding.executeCall(); + assertEquals(200, response.code()); + } + + @Test + public void intersectionSearch_AddIntersectionToQuery() throws IOException { + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .intersectionStreets("Market Street", "Fremont Street") + .proximity("-122.39738575285674,37.792514711136945") + .baseUrl(mockUrl.toString()) + .build(); + assertNotNull(mapboxGeocoding); + assertTrue(mapboxGeocoding.cloneCall().request().url().toString() + .contains("Market%20Street%20and%20Fremont%20Street")); + } } diff --git a/services-geocoding/src/test/resources/forward_intersection.json b/services-geocoding/src/test/resources/forward_intersection.json new file mode 100644 index 000000000..c9a27fa1c --- /dev/null +++ b/services-geocoding/src/test/resources/forward_intersection.json @@ -0,0 +1 @@ +{"type":"FeatureCollection","query":["market","street","and","fremont","street"],"features":[{"id":"address.1986547056502524","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"intersection"},"text":"Fremont Street","place_name":"Market Street and Fremont Street, San Francisco, California 94105, United States","center":[-122.3982976,37.791734],"geometry":{"type":"Point","coordinates":[-122.3982976,37.791734]},"context":[{"id":"neighborhood.293324","text":"South Beach"},{"id":"postcode.17577055718678700","text":"94105"},{"id":"place.15734669613361910","wikidata":"Q62","text":"San Francisco"},{"id":"region.11319063928738010","short_code":"US-CA","wikidata":"Q99","text":"California"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.2168135640082828","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"intersection"},"text":"Fremont Street","place_name":"Market Street and Fremont Street, Erie, Pennsylvania 16510, United States","center":[-80.0112744,42.139934],"geometry":{"type":"Point","coordinates":[-80.0112744,42.139934]},"context":[{"id":"neighborhood.268738","text":"Brookside"},{"id":"postcode.7318118112165310","text":"16510"},{"id":"place.10004124579967850","wikidata":"Q234061","text":"Erie"},{"id":"region.2157738952111630","short_code":"US-PA","wikidata":"Q1400","text":"Pennsylvania"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.4254940365412868","type":"Feature","place_type":["address"],"relevance":0.988636,"properties":{"accuracy":"intersection"},"text":"Tremont Street","place_name":"Market Street and Tremont Street, Lynn, Massachusetts 01901, United States","center":[-70.9496726,42.4633684],"geometry":{"type":"Point","coordinates":[-70.9496726,42.4633684]},"context":[{"id":"neighborhood.287332","text":"Central Square Area"},{"id":"postcode.8079700663915320","text":"01901"},{"id":"place.5083986385572820","wikidata":"Q49188","text":"Lynn"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.7308702273993364","type":"Feature","place_type":["address"],"relevance":0.988636,"properties":{"accuracy":"intersection"},"text":"Tremont Street","place_name":"Market Street and Tremont Street, Presidio, Texas 79845, United States","center":[-104.3747124,29.5627643],"geometry":{"type":"Point","coordinates":[-104.3747124,29.5627643]},"context":[{"id":"postcode.254811532177250","text":"79845"},{"id":"place.8840105903998060","wikidata":"Q970777","text":"Presidio"},{"id":"region.5362387429342410","short_code":"US-TX","wikidata":"Q1439","text":"Texas"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.1764530839718556","type":"Feature","place_type":["address"],"relevance":0.4016,"properties":{"accuracy":"street"},"text":"2nd & Fremont St","place_name":"2nd & Fremont St, Royal, Nebraska 68773, United States","center":[-98.1238105,42.3344656],"geometry":{"type":"Point","coordinates":[-98.1238105,42.3344656]},"context":[{"id":"postcode.11302267114803110","text":"68773"},{"id":"place.13924027642746770","text":"Royal"},{"id":"region.8407900583987740","short_code":"US-NE","wikidata":"Q1553","text":"Nebraska"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]}],"attribution":"NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."} \ No newline at end of file From 0f5eadbc4c86b1d29eb86c9c5e1e393cfeb5d6f3 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Tue, 17 Sep 2019 11:14:05 +0300 Subject: [PATCH 2/6] [geocoding] Set geocodingType to address by default when intersectionStreet is used. --- .../api/geocoding/v5/MapboxGeocoding.java | 17 ++++ .../api/geocoding/v5/MapboxGeocodingTest.java | 77 +++++++++++++++---- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java index d364d1508..5224b8ec1 100644 --- a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java +++ b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java @@ -611,6 +611,7 @@ public MapboxGeocoding build() { if (intersectionStreets.size() == 2) { query(TextUtils.join(" and ", intersectionStreets.toArray())); + geocodingTypes(GeocodingCriteria.TYPE_ADDRESS); } // Generate build so that we can check that values are valid. @@ -627,6 +628,22 @@ public MapboxGeocoding build() { && geocoding.limit() != null && !geocoding.limit().equals("1")) { throw new ServicesException("Limit must be combined with a single type parameter"); } + + if (intersectionStreets.size() == 2) { + if (!(geocoding.mode().equals(GeocodingCriteria.MODE_PLACES) + || geocoding.mode().equals(GeocodingCriteria.MODE_PLACES_PERMANENT))) { + throw new ServicesException("Geocoding mode must be " + GeocodingCriteria.MODE_PLACES + + " or " + GeocodingCriteria.MODE_PLACES_PERMANENT + " for intersection search."); + } + if (TextUtils.isEmpty(geocoding.geocodingTypes()) + || !geocoding.geocodingTypes().equals(GeocodingCriteria.TYPE_ADDRESS)) { + throw new ServicesException("Geocoding type must be set to " + + GeocodingCriteria.TYPE_ADDRESS + " for intersection search."); + } + if (TextUtils.isEmpty(geocoding.proximity())) { + throw new ServicesException("Geocoding proximity must be set for intersection search."); + } + } return geocoding; } } diff --git a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java index a3fb0da4b..216d68809 100644 --- a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java +++ b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java @@ -58,7 +58,7 @@ public void executeBatchCall_exceptionThrownWhenModeNotSetCorrectly() throws Exc } @Test - public void build_noAccessTokenExceptionThrown() throws Exception { + public void build_noAccessTokenExceptionThrown() { thrown.expect(IllegalStateException.class); thrown.expectMessage("Missing required properties: accessToken"); MapboxGeocoding.builder() @@ -68,7 +68,7 @@ public void build_noAccessTokenExceptionThrown() throws Exception { } @Test - public void build_invalidAccessTokenExceptionThrown() throws Exception { + public void build_invalidAccessTokenExceptionThrown() { thrown.expect(ServicesException.class); thrown.expectMessage( startsWith("Using Mapbox Services requires setting a valid access token.")); @@ -104,7 +104,7 @@ public void query_acceptsPointsCorrectly() throws Exception { } @Test - public void baseUrl_doesChangeTheRequestUrl() throws Exception { + public void baseUrl_doesChangeTheRequestUrl() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl("https://foobar.com") @@ -115,7 +115,7 @@ public void baseUrl_doesChangeTheRequestUrl() throws Exception { } @Test - public void country_localeCountryConvertsCorrectly() throws Exception { + public void country_localeCountryConvertsCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -126,7 +126,7 @@ public void country_localeCountryConvertsCorrectly() throws Exception { } @Test - public void country_localeCountryHandlesMultipleCountriesCorrectly() throws Exception { + public void country_localeCountryHandlesMultipleCountriesCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -139,7 +139,7 @@ public void country_localeCountryHandlesMultipleCountriesCorrectly() throws Exce } @Test - public void proximity_doesGetAddedToUrlCorrectly() throws Exception { + public void proximity_doesGetAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -151,7 +151,7 @@ public void proximity_doesGetAddedToUrlCorrectly() throws Exception { } @Test - public void geocodingTypes_getsAddedToUrlCorrectly() throws Exception { + public void geocodingTypes_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -163,7 +163,7 @@ public void geocodingTypes_getsAddedToUrlCorrectly() throws Exception { } @Test - public void autocomplete_getsAddedToUrlCorrectly() throws Exception { + public void autocomplete_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -175,7 +175,7 @@ public void autocomplete_getsAddedToUrlCorrectly() throws Exception { } @Test - public void bbox_getsFormattedCorrectlyForUrl() throws Exception { + public void bbox_getsFormattedCorrectlyForUrl() { BoundingBox bbox = BoundingBox.fromLngLats( -77.083056, 38.908611, -76.997778, 38.959167); MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() @@ -189,7 +189,7 @@ public void bbox_getsFormattedCorrectlyForUrl() throws Exception { } @Test - public void bbox_asPoints_getsFormattedCorrectlyForUrl() throws Exception { + public void bbox_asPoints_getsFormattedCorrectlyForUrl() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -204,7 +204,7 @@ public void bbox_asPoints_getsFormattedCorrectlyForUrl() throws Exception { } @Test - public void limit_getsAddedToUrlCorrectly() throws Exception { + public void limit_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -216,7 +216,7 @@ public void limit_getsAddedToUrlCorrectly() throws Exception { } @Test - public void language_getsConvertedToUrlCorrectly() throws Exception { + public void language_getsConvertedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -228,7 +228,7 @@ public void language_getsConvertedToUrlCorrectly() throws Exception { } @Test - public void clientAppName_hasAppInString() throws Exception { + public void clientAppName_hasAppInString() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) @@ -240,7 +240,7 @@ public void clientAppName_hasAppInString() throws Exception { } @Test - public void reverseMode_getsAddedToUrlCorrectly() throws Exception { + public void reverseMode_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl("https://foobar.com") @@ -261,7 +261,7 @@ public void reverseMode_getsAddedToUrlCorrectly() throws Exception { } @Test - public void reverseMode_onlyLimit1_Allowed() throws Exception { + public void reverseMode_onlyLimit1_Allowed() { thrown.expect(ServicesException.class); thrown.expectMessage(startsWith("Limit must be combined with a single type")); MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() @@ -287,7 +287,7 @@ public void fuzzyMatchSanity() throws Exception { } @Test - public void fuzzyMatch_getsAddedToUrlCorrectly() throws Exception { + public void fuzzyMatch_getsAddedToUrlCorrectly() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .query("wahsington") @@ -305,6 +305,7 @@ public void intersectionSearchSanity() throws IOException { .accessToken(ACCESS_TOKEN) .intersectionStreets("Market Street", "Fremont Street") .proximity("-122.39738575285674,37.792514711136945") + .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS) .baseUrl(mockUrl.toString()) .build(); assertNotNull(mapboxGeocoding); @@ -313,15 +314,57 @@ public void intersectionSearchSanity() throws IOException { } @Test - public void intersectionSearch_AddIntersectionToQuery() throws IOException { + public void intersectionSearch_AddIntersectionToQuery() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .intersectionStreets("Market Street", "Fremont Street") .proximity("-122.39738575285674,37.792514711136945") + .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS) .baseUrl(mockUrl.toString()) .build(); assertNotNull(mapboxGeocoding); assertTrue(mapboxGeocoding.cloneCall().request().url().toString() .contains("Market%20Street%20and%20Fremont%20Street")); } + + @Test + public void intersectionSearch_WrongMode() { + thrown.expect(ServicesException.class); + thrown.expectMessage( + startsWith("Geocoding mode must be mapbox.places or mapbox.places-permanent for intersection search.")); + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .mode("RandomMode") + .intersectionStreets("Market Street", "Fremont Street") + .proximity("-122.39738575285674,37.792514711136945") + .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS) + .baseUrl(mockUrl.toString()) + .build(); + } + + @Test + public void intersectionSearch_AutoSetGeocodingType() { + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .intersectionStreets("Market Street", "Fremont Street") + .proximity("-122.39738575285674,37.792514711136945") + .baseUrl(mockUrl.toString()) + .build(); + assertNotNull(mapboxGeocoding); + assertTrue(mapboxGeocoding.cloneCall().request().url().toString() + .contains("types=address")); + } + + @Test + public void intersectionSearch_EmptyPromixity() { + thrown.expect(ServicesException.class); + thrown.expectMessage( + startsWith("Geocoding proximity must be set for intersection search.")); + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .intersectionStreets("Market Street", "Fremont Street") + .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS) + .baseUrl(mockUrl.toString()) + .build(); + } } From ffa7cc9ac7f8076d21b127e74872441b5dfecf45 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Tue, 17 Sep 2019 19:39:45 +0300 Subject: [PATCH 3/6] [geocoding] Fixes after @langsmith's review. --- .../api/geocoding/v5/MapboxGeocoding.java | 19 +- .../api/geocoding/v5/MapboxGeocodingTest.java | 2 +- .../test/resources/forward_intersection.json | 260 +++++++++++++++++- 3 files changed, 270 insertions(+), 11 deletions(-) diff --git a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java index 5224b8ec1..9704d30a2 100644 --- a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java +++ b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java @@ -587,13 +587,14 @@ public abstract Builder reverseMode( /** * Specify the two street names for intersection search. * - * @param streetOne First street name of the intersection - * @param streetTwo Second street name of the intersection + * @param streetOneName First street name of the intersection + * @param streetTwoName Second street name of the intersection * @return this builder for chaining options together */ - public Builder intersectionStreets(@NonNull String streetOne, @NonNull String streetTwo) { - intersectionStreets.add(streetOne); - intersectionStreets.add(streetTwo); + public Builder intersectionStreets(@NonNull String streetOneName, + @NonNull String streetTwoName) { + intersectionStreets.add(streetOneName); + intersectionStreets.add(streetTwoName); return this; } @@ -632,13 +633,13 @@ public MapboxGeocoding build() { if (intersectionStreets.size() == 2) { if (!(geocoding.mode().equals(GeocodingCriteria.MODE_PLACES) || geocoding.mode().equals(GeocodingCriteria.MODE_PLACES_PERMANENT))) { - throw new ServicesException("Geocoding mode must be " + GeocodingCriteria.MODE_PLACES - + " or " + GeocodingCriteria.MODE_PLACES_PERMANENT + " for intersection search."); + throw new ServicesException("Geocoding mode must be GeocodingCriteria.MODE_PLACES " + + "or GeocodingCriteria.MODE_PLACES_PERMANENT for intersection search."); } if (TextUtils.isEmpty(geocoding.geocodingTypes()) || !geocoding.geocodingTypes().equals(GeocodingCriteria.TYPE_ADDRESS)) { - throw new ServicesException("Geocoding type must be set to " - + GeocodingCriteria.TYPE_ADDRESS + " for intersection search."); + throw new ServicesException("Geocoding type must be set to Geocoding " + + "Criteria.TYPE_ADDRESS for intersection search."); } if (TextUtils.isEmpty(geocoding.proximity())) { throw new ServicesException("Geocoding proximity must be set for intersection search."); diff --git a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java index 216d68809..453f3a5cc 100644 --- a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java +++ b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java @@ -331,7 +331,7 @@ public void intersectionSearch_AddIntersectionToQuery() { public void intersectionSearch_WrongMode() { thrown.expect(ServicesException.class); thrown.expectMessage( - startsWith("Geocoding mode must be mapbox.places or mapbox.places-permanent for intersection search.")); + startsWith("Geocoding mode must be GeocodingCriteria.MODE_PLACES or GeocodingCriteria.MODE_PLACES_PERMANENT for intersection search.")); MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .mode("RandomMode") diff --git a/services-geocoding/src/test/resources/forward_intersection.json b/services-geocoding/src/test/resources/forward_intersection.json index c9a27fa1c..92545133b 100644 --- a/services-geocoding/src/test/resources/forward_intersection.json +++ b/services-geocoding/src/test/resources/forward_intersection.json @@ -1 +1,259 @@ -{"type":"FeatureCollection","query":["market","street","and","fremont","street"],"features":[{"id":"address.1986547056502524","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"intersection"},"text":"Fremont Street","place_name":"Market Street and Fremont Street, San Francisco, California 94105, United States","center":[-122.3982976,37.791734],"geometry":{"type":"Point","coordinates":[-122.3982976,37.791734]},"context":[{"id":"neighborhood.293324","text":"South Beach"},{"id":"postcode.17577055718678700","text":"94105"},{"id":"place.15734669613361910","wikidata":"Q62","text":"San Francisco"},{"id":"region.11319063928738010","short_code":"US-CA","wikidata":"Q99","text":"California"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.2168135640082828","type":"Feature","place_type":["address"],"relevance":1,"properties":{"accuracy":"intersection"},"text":"Fremont Street","place_name":"Market Street and Fremont Street, Erie, Pennsylvania 16510, United States","center":[-80.0112744,42.139934],"geometry":{"type":"Point","coordinates":[-80.0112744,42.139934]},"context":[{"id":"neighborhood.268738","text":"Brookside"},{"id":"postcode.7318118112165310","text":"16510"},{"id":"place.10004124579967850","wikidata":"Q234061","text":"Erie"},{"id":"region.2157738952111630","short_code":"US-PA","wikidata":"Q1400","text":"Pennsylvania"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.4254940365412868","type":"Feature","place_type":["address"],"relevance":0.988636,"properties":{"accuracy":"intersection"},"text":"Tremont Street","place_name":"Market Street and Tremont Street, Lynn, Massachusetts 01901, United States","center":[-70.9496726,42.4633684],"geometry":{"type":"Point","coordinates":[-70.9496726,42.4633684]},"context":[{"id":"neighborhood.287332","text":"Central Square Area"},{"id":"postcode.8079700663915320","text":"01901"},{"id":"place.5083986385572820","wikidata":"Q49188","text":"Lynn"},{"id":"region.6776276020561540","short_code":"US-MA","wikidata":"Q771","text":"Massachusetts"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.7308702273993364","type":"Feature","place_type":["address"],"relevance":0.988636,"properties":{"accuracy":"intersection"},"text":"Tremont Street","place_name":"Market Street and Tremont Street, Presidio, Texas 79845, United States","center":[-104.3747124,29.5627643],"geometry":{"type":"Point","coordinates":[-104.3747124,29.5627643]},"context":[{"id":"postcode.254811532177250","text":"79845"},{"id":"place.8840105903998060","wikidata":"Q970777","text":"Presidio"},{"id":"region.5362387429342410","short_code":"US-TX","wikidata":"Q1439","text":"Texas"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]},{"id":"address.1764530839718556","type":"Feature","place_type":["address"],"relevance":0.4016,"properties":{"accuracy":"street"},"text":"2nd & Fremont St","place_name":"2nd & Fremont St, Royal, Nebraska 68773, United States","center":[-98.1238105,42.3344656],"geometry":{"type":"Point","coordinates":[-98.1238105,42.3344656]},"context":[{"id":"postcode.11302267114803110","text":"68773"},{"id":"place.13924027642746770","text":"Royal"},{"id":"region.8407900583987740","short_code":"US-NE","wikidata":"Q1553","text":"Nebraska"},{"id":"country.9053006287256050","short_code":"us","wikidata":"Q30","text":"United States"}]}],"attribution":"NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."} \ No newline at end of file +{ + "type": "FeatureCollection", + "query": [ + "market", + "street", + "and", + "fremont", + "street" + ], + "features": [ + { + "id": "address.1986547056502524", + "type": "Feature", + "place_type": [ + "address" + ], + "relevance": 1, + "properties": { + "accuracy": "intersection" + }, + "text": "Fremont Street", + "place_name": "Market Street and Fremont Street, San Francisco, California 94105, United States", + "center": [ + -122.3982976, + 37.791734 + ], + "geometry": { + "type": "Point", + "coordinates": [ + -122.3982976, + 37.791734 + ] + }, + "context": [ + { + "id": "neighborhood.293324", + "text": "South Beach" + }, + { + "id": "postcode.17577055718678700", + "text": "94105" + }, + { + "id": "place.15734669613361910", + "wikidata": "Q62", + "text": "San Francisco" + }, + { + "id": "region.11319063928738010", + "short_code": "US-CA", + "wikidata": "Q99", + "text": "California" + }, + { + "id": "country.9053006287256050", + "short_code": "us", + "wikidata": "Q30", + "text": "United States" + } + ] + }, + { + "id": "address.2168135640082828", + "type": "Feature", + "place_type": [ + "address" + ], + "relevance": 1, + "properties": { + "accuracy": "intersection" + }, + "text": "Fremont Street", + "place_name": "Market Street and Fremont Street, Erie, Pennsylvania 16510, United States", + "center": [ + -80.0112744, + 42.139934 + ], + "geometry": { + "type": "Point", + "coordinates": [ + -80.0112744, + 42.139934 + ] + }, + "context": [ + { + "id": "neighborhood.268738", + "text": "Brookside" + }, + { + "id": "postcode.7318118112165310", + "text": "16510" + }, + { + "id": "place.10004124579967850", + "wikidata": "Q234061", + "text": "Erie" + }, + { + "id": "region.2157738952111630", + "short_code": "US-PA", + "wikidata": "Q1400", + "text": "Pennsylvania" + }, + { + "id": "country.9053006287256050", + "short_code": "us", + "wikidata": "Q30", + "text": "United States" + } + ] + }, + { + "id": "address.4254940365412868", + "type": "Feature", + "place_type": [ + "address" + ], + "relevance": 0.988636, + "properties": { + "accuracy": "intersection" + }, + "text": "Tremont Street", + "place_name": "Market Street and Tremont Street, Lynn, Massachusetts 01901, United States", + "center": [ + -70.9496726, + 42.4633684 + ], + "geometry": { + "type": "Point", + "coordinates": [ + -70.9496726, + 42.4633684 + ] + }, + "context": [ + { + "id": "neighborhood.287332", + "text": "Central Square Area" + }, + { + "id": "postcode.8079700663915320", + "text": "01901" + }, + { + "id": "place.5083986385572820", + "wikidata": "Q49188", + "text": "Lynn" + }, + { + "id": "region.6776276020561540", + "short_code": "US-MA", + "wikidata": "Q771", + "text": "Massachusetts" + }, + { + "id": "country.9053006287256050", + "short_code": "us", + "wikidata": "Q30", + "text": "United States" + } + ] + }, + { + "id": "address.7308702273993364", + "type": "Feature", + "place_type": [ + "address" + ], + "relevance": 0.988636, + "properties": { + "accuracy": "intersection" + }, + "text": "Tremont Street", + "place_name": "Market Street and Tremont Street, Presidio, Texas 79845, United States", + "center": [ + -104.3747124, + 29.5627643 + ], + "geometry": { + "type": "Point", + "coordinates": [ + -104.3747124, + 29.5627643 + ] + }, + "context": [ + { + "id": "postcode.254811532177250", + "text": "79845" + }, + { + "id": "place.8840105903998060", + "wikidata": "Q970777", + "text": "Presidio" + }, + { + "id": "region.5362387429342410", + "short_code": "US-TX", + "wikidata": "Q1439", + "text": "Texas" + }, + { + "id": "country.9053006287256050", + "short_code": "us", + "wikidata": "Q30", + "text": "United States" + } + ] + }, + { + "id": "address.1764530839718556", + "type": "Feature", + "place_type": [ + "address" + ], + "relevance": 0.4016, + "properties": { + "accuracy": "street" + }, + "text": "2nd & Fremont St", + "place_name": "2nd & Fremont St, Royal, Nebraska 68773, United States", + "center": [ + -98.1238105, + 42.3344656 + ], + "geometry": { + "type": "Point", + "coordinates": [ + -98.1238105, + 42.3344656 + ] + }, + "context": [ + { + "id": "postcode.11302267114803110", + "text": "68773" + }, + { + "id": "place.13924027642746770", + "text": "Royal" + }, + { + "id": "region.8407900583987740", + "short_code": "US-NE", + "wikidata": "Q1553", + "text": "Nebraska" + }, + { + "id": "country.9053006287256050", + "short_code": "us", + "wikidata": "Q30", + "text": "United States" + } + ] + } + ], + "attribution": "NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare." +} \ No newline at end of file From 7a74d3e65fea43f3ebede41fb4a40e77d2d9d271 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Wed, 18 Sep 2019 11:05:16 +0300 Subject: [PATCH 4/6] [geocoding] Add @since annotation. Co-Authored-By: Langston Smith --- .../main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java | 1 + 1 file changed, 1 insertion(+) diff --git a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java index 9704d30a2..e5a6ab537 100644 --- a/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java +++ b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/MapboxGeocoding.java @@ -590,6 +590,7 @@ public abstract Builder reverseMode( * @param streetOneName First street name of the intersection * @param streetTwoName Second street name of the intersection * @return this builder for chaining options together + * @since 4.10.0 */ public Builder intersectionStreets(@NonNull String streetOneName, @NonNull String streetTwoName) { From 9d8994ce9eee201fcdd69cd9ef9dd54484004c59 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Wed, 18 Sep 2019 11:15:56 +0300 Subject: [PATCH 5/6] [geocoding] Add test case for checking key word . --- .../api/geocoding/v5/MapboxGeocodingTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java index 453f3a5cc..59a7b3130 100644 --- a/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java +++ b/services-geocoding/src/test/java/com/mapbox/api/geocoding/v5/MapboxGeocodingTest.java @@ -313,6 +313,19 @@ public void intersectionSearchSanity() throws IOException { assertEquals(200, response.code()); } + @Test + public void intersectionSearchAndAddedCorrectly() { + MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() + .accessToken(ACCESS_TOKEN) + .intersectionStreets("Street one", "Street two") + .proximity("-122.39738575285674,37.792514711136945") + .geocodingTypes(GeocodingCriteria.TYPE_ADDRESS) + .baseUrl(mockUrl.toString()) + .build(); + assertNotNull(mapboxGeocoding); + assertTrue(mapboxGeocoding.cloneCall().request().url().toString().contains("and")); + } + @Test public void intersectionSearch_AddIntersectionToQuery() { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() From 61dbaa4c7a1ac8e36084ae1cec37a7f0256efa31 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Wed, 18 Sep 2019 11:21:54 +0300 Subject: [PATCH 6/6] [geocoding] Add change log. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e73fa660..472abd0c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Mapbox welcomes participation and contributions from everyone. +### master + +- Added intersection search support to MapboxGeocoding [#1074](https://github.com/mapbox/mapbox-java/pull/1074) + ### v4.9.0-alpha.1 - September 4, 2019 - Fixed up bintray publish script, generate sources and javadoc jars #1065