From 949a0d82bff00bf5c85db8e34936d2baae5663d7 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 31 Jan 2024 14:54:12 -0500 Subject: [PATCH 1/7] Add nullable Country.default, add Discover.Options(country, proximity, origin) params - SSDK-399 - Add Country.default: Self? to auto-detect the current device region and provide a value if found - Add proximity and origin CLLocationCoordinate2D fields to Discover.Option and forward these to SearchOption parameters --- CHANGELOG.md | 1 + .../Common/Models/Country/Country.swift | 21 ++++++++++++++++++- .../Use Cases/Discover API/Discover.swift | 11 ++++++++-- .../Models/Discover+Options.swift | 17 ++++++++++++++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41f04cd67..c2e7134ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Guide: https://keepachangelog.com/en/1.0.0/ +- [Discover] Add support for country, proximity, and origin parameters in Discover.Options search parameters. This fixes an issue when using search-along-route to query category results. - [Discover] Fix charging station category canonical ID - [SearchUI] Rename MapboxPanelController.Configuration to .PanelConfiguration. This disambiguates PanelConfiguration from the broader Configuration struct. - [Core] Update SwiftLint to 0.54.0 and SwiftFormat to 0.52.11 diff --git a/Sources/MapboxSearch/PublicAPI/Common/Models/Country/Country.swift b/Sources/MapboxSearch/PublicAPI/Common/Models/Country/Country.swift index 169fe908b..f28ef6856 100644 --- a/Sources/MapboxSearch/PublicAPI/Common/Models/Country/Country.swift +++ b/Sources/MapboxSearch/PublicAPI/Common/Models/Country/Country.swift @@ -3,7 +3,7 @@ import Foundation public struct Country: Equatable { public let countryCode: String - /// Country model initializier + /// Country model initializer /// - Parameter countryCode: Permitted values are ISO 3166-1 alpha 2 country codes (e.g. US, DE, GB) public init?(countryCode: String) { guard ISO3166_1_alpha2(rawValue: countryCode.uppercased()) != nil else { @@ -12,4 +12,23 @@ public struct Country: Equatable { self.countryCode = countryCode.lowercased() } + + init(code: ISO3166_1_alpha2) { + self.countryCode = code.rawValue.lowercased() + } + + /// Detect the system region ISO3166\_1\_Alpha2 identifier and return an instance for it + static var `default`: Self? { + if #available(iOS 16, *) { + return Country(countryCode: Locale.current.region?.identifier ?? "") + } else { + let regionComponents = Locale.current.identifier.components(separatedBy: "_") + if regionComponents.count >= 2 { + let countryIdentifier = regionComponents[1] + return Country(countryCode: countryIdentifier) + } else { + return nil + } + } + } } diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift index 0e1818670..c5811927e 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift @@ -59,9 +59,11 @@ extension Discover { userActivityReporter.reportActivity(forComponent: "discover-search-nearby") let searchOptions = SearchOptions( + countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, - proximity: proximity + proximity: proximity, + origin: options.origin ) search(for: query, with: searchOptions, completion: completion) @@ -85,10 +87,12 @@ extension Discover { userActivityReporter.reportActivity(forComponent: "discover-search-in-area") let searchOptions = SearchOptions( + countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, proximity: proximity, - boundingBox: region + boundingBox: region, + origin: options.origin ) search(for: query, with: searchOptions, completion: completion) @@ -110,8 +114,11 @@ extension Discover { userActivityReporter.reportActivity(forComponent: "discover-search-along-the-route") let searchOptions = SearchOptions( + countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, + proximity: options.proximity, + origin: options.origin, routeOptions: route ) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift index bbaf21d9f..6721ee480 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift @@ -15,12 +15,27 @@ extension Discover { /// English (en) language parameter, but Frankreich (“France”) with a German (de) language parameter. public let language: Language + /// See ``MapboxSearch.Country.ISO3166_1_alpha2`` for the list of ISO 3166 alpha 2 country codes. + /// The default value will be selected from the Country.ISO3166\_1\_alpha2 identifiers based on the current + /// locale identifier or nil if no match is found. + public let country: Country? + + public let proximity: CLLocationCoordinate2D? + + public let origin: CLLocationCoordinate2D? + public init( limit: Int = 10, - language: Language? = nil + language: Language? = nil, + country: Country? = nil, + proximity: CLLocationCoordinate2D? = nil, + origin: CLLocationCoordinate2D? = nil ) { self.limit = limit self.language = language ?? .default + self.country = country ?? .default + self.proximity = proximity + self.origin = origin } } } From bab5844ef1c3441d232aae8444c28221da1bfe58 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 31 Jan 2024 18:12:25 -0500 Subject: [PATCH 2/7] Add test to ensure Discover with Search-along-route works correctly - SSDK-399 --- MapboxSearch.xcodeproj/project.pbxproj | 12 + .../DiscoverIntegrationTests.swift | 46 ++ .../MockWebServer/MockResponse.swift | 11 +- .../MockWebServer/MockWebServer.swift | 9 +- .../category-hotel-search-along-route-jp.json | 687 ++++++++++++++++++ 5 files changed, 759 insertions(+), 6 deletions(-) create mode 100644 Tests/MapboxSearchIntegrationTests/DiscoverIntegrationTests.swift create mode 100644 Tests/MapboxSearchUITests/MockWebServer/category-hotel-search-along-route-jp.json diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index f6dd3380f..5fa0dad67 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ 043A3D4D2B30F38300DB681B /* CoreAddress+AddressComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */; }; + 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; + 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; + 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; + 04AB0B7B2B6AF43E00FDE7D5 /* DiscoverIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */; }; 04C0848D2B4C82F3002F9C69 /* SdkInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */; }; 04E5FF962B48828500DADC18 /* SearchAddressCountry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */; }; 04E5FF992B48829200DADC18 /* SearchAddressRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */; }; @@ -480,6 +484,8 @@ /* Begin PBXFileReference section */ 043A3D4C2B30F38300DB681B /* CoreAddress+AddressComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreAddress+AddressComponents.swift"; sourceTree = ""; }; + 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = ""; }; + 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */ = {isa = PBXFileReference; explicitFileType = text.json; path = "category-hotel-search-along-route-jp.json"; sourceTree = ""; }; 04C0848C2B4C82F3002F9C69 /* SdkInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SdkInformation.swift; sourceTree = ""; }; 04E5FF952B48828500DADC18 /* SearchAddressCountry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressCountry.swift; sourceTree = ""; }; 04E5FF982B48829200DADC18 /* SearchAddressRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchAddressRegion.swift; sourceTree = ""; }; @@ -1340,6 +1346,7 @@ 2CE1B9FA2A13D412005B043F /* address-retrieve-san-francisco.json */, 2CE1B9F92A13D412005B043F /* address-suggestions-san-francisco.json */, 2CD8AC5129F28D6900C47BE4 /* retrieve-poi.json */, + 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */, 2CD8AC4029F1D38800C47BE4 /* suggestions-category-with-coordinates.json */, 2CD8AC4129F1D38800C47BE4 /* suggestions-with-coordinates.json */, 2CD8AC4229F1D38800C47BE4 /* suggestions-with-mixed-coordinates.json */, @@ -1456,6 +1463,7 @@ F9274FF3273AA72800708F37 /* OfflineIntegrationTests.swift */, F9ACA6162642C18200F50CD4 /* SearchEngineIntegrationTests.swift */, F99190422645ABE6009927A6 /* CategorySearchEngineIntegrationTests.swift */, + 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */, F9C5572C2670C88E00BE8B94 /* Info.plist */, ); path = MapboxSearchIntegrationTests; @@ -2033,6 +2041,7 @@ F94FFA4A264547CD0019ED9B /* retrieve-multi.json in Resources */, 2CD8AC4429F1D38800C47BE4 /* suggestions-category-with-coordinates.json in Resources */, F9B62CCB264BCC2600492999 /* suggestions-empty.json in Resources */, + 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */, F9ACA6182642C48C00F50CD4 /* recursion.json in Resources */, F9B62CC8264BC61600492999 /* category-cafe.json in Resources */, F9ACA6192642C49000F50CD4 /* retrieve-category.json in Resources */, @@ -2061,6 +2070,7 @@ F907440F261B00000091899C /* suggestions-san-francisco.json in Resources */, F94FFA4826453D410019ED9B /* reverse-geocoding.json in Resources */, 2CD8AC4B29F1D38800C47BE4 /* suggestions-with-mixed-coordinates.json in Resources */, + 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */, 2CD8AC5429F28D6900C47BE4 /* retrieve-poi.json in Resources */, F9074425261B0DF70091899C /* retrieve-san-francisco.json in Resources */, 2CD8AC4829F1D38800C47BE4 /* suggestions-with-coordinates.json in Resources */, @@ -2079,6 +2089,7 @@ F9C557A42670CB0400BE8B94 /* retrieve-multi.json in Resources */, 2CD8AC4329F1D38800C47BE4 /* suggestions-category-with-coordinates.json in Resources */, F9C557A52670CB0400BE8B94 /* suggestions-empty.json in Resources */, + 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */, F9C557A62670CB0400BE8B94 /* recursion.json in Resources */, F9C557A72670CB0400BE8B94 /* category-cafe.json in Resources */, F9C557A82670CB0400BE8B94 /* retrieve-category.json in Resources */, @@ -2589,6 +2600,7 @@ F9C557C12670CD8C00BE8B94 /* CoreSearchOptions+Samples.swift in Sources */, 1420F31C29A2800300D4A511 /* CoreSearchResultStub+Samples.swift in Sources */, F9C557B72670CC5600BE8B94 /* CoreSearchResultStub.swift in Sources */, + 04AB0B7B2B6AF43E00FDE7D5 /* DiscoverIntegrationTests.swift in Sources */, F9C557BF2670CD4300BE8B94 /* CoreRequestOptions+Samples.swift in Sources */, F9C557BB2670CCC000BE8B94 /* SearchResultType+Extensions.swift in Sources */, F9C557BA2670CCAB00BE8B94 /* TestDataProviderRecord.swift in Sources */, diff --git a/Tests/MapboxSearchIntegrationTests/DiscoverIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/DiscoverIntegrationTests.swift new file mode 100644 index 000000000..9bf79471e --- /dev/null +++ b/Tests/MapboxSearchIntegrationTests/DiscoverIntegrationTests.swift @@ -0,0 +1,46 @@ +import CoreLocation +@testable import MapboxSearch +import XCTest + +class DiscoverIntegrationTests: MockServerTestCase { + lazy var searchEngine = Discover(locationProvider: DefaultLocationProvider()) + + func testCategorySearchAlongRouteWithCountryProximityOrigin() throws { + try server.setResponse(.categoryHotelSearchAlongRoute_JP) + let expectation = XCTestExpectation(description: "Expecting results") + + let coordinate1 = CLLocationCoordinate2D(latitude: 35.655614, longitude: 139.7081684) + let coordinate2 = CLLocationCoordinate2D(latitude: 35.6881616, longitude: 139.6994339) + let coordinates = [coordinate1, coordinate2] + + let mapboxSearchRoute = MapboxSearch.Route(coordinates: coordinates) + let rOptions: MapboxSearch.RouteOptions = RouteOptions(route: mapboxSearchRoute, time: 1000) + + let discoverOptions = Discover.Options( + limit: 10, + language: nil, + country: Country(countryCode: "jp"), + proximity: CLLocationCoordinate2D( + latitude: 35.6634363, + longitude: 139.7394536 + ), + origin: CLLocationCoordinate2D(latitude: 35.66580, longitude: 139.74609) + ) + + searchEngine.search( + for: Discover.Query.Category.canonicalName("hotel"), + route: rOptions, + options: discoverOptions + ) { result in + switch result { + case .success(let searchResults): + XCTAssertFalse(searchResults.isEmpty) + expectation.fulfill() + case .failure: + XCTFail("Error not expected") + } + expectation.fulfill() + } + wait(for: [expectation], timeout: 10) + } +} diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift index 3c8baf256..f8d7336e5 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockResponse.swift @@ -6,7 +6,8 @@ enum MockResponse { case retrieve case reverse case multiRetrieve = "retrieve/multi" - case category + case categoryCafe = "cafe" + case categoryHotel = "hotel" case addressSuggest = "autofill/suggest" case addressRetrieve = "autofill/retrieve" } @@ -30,6 +31,7 @@ enum MockResponse { case recursion case reverseGeocoding case categoryCafe + case categoryHotelSearchAlongRoute_JP var path: String { let bundle = Bundle(for: MockWebServer.self) @@ -64,6 +66,8 @@ enum MockResponse { return bundle.path(forResource: "retrieve-multi", ofType: "json")! case .categoryCafe: return bundle.path(forResource: "category-cafe", ofType: "json")! + case .categoryHotelSearchAlongRoute_JP: + return bundle.path(forResource: "category-hotel-search-along-route-jp", ofType: "json")! case .suggestAddressSanFrancisco: return bundle.path(forResource: "address-suggestions-san-francisco", ofType: "json")! case .retrieveAddressSanFrancisco: @@ -102,7 +106,10 @@ enum MockResponse { return .multiRetrieve case .categoryCafe: - return .category + return .categoryCafe + + case .categoryHotelSearchAlongRoute_JP: + return .categoryHotel } } } diff --git a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift index 75f304e8b..5f933a4f8 100644 --- a/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift +++ b/Tests/MapboxSearchUITests/MockWebServer/MockWebServer.swift @@ -60,10 +60,10 @@ extension MockWebServer { fileprivate static func httpMethod(for endpoint: MockResponse.Endpoint) -> HTTPMethod { switch endpoint { - case .suggest, .category, .reverse, .addressSuggest, .addressRetrieve: + case .suggest, .categoryCafe, .reverse, .addressSuggest, .addressRetrieve: return .get - case .retrieve, .multiRetrieve: + case .retrieve, .multiRetrieve, .categoryHotel: return .post } } @@ -75,8 +75,9 @@ extension MockWebServer { case .suggest: path += "/:query" - case .category: - path += "/:category" + case .categoryCafe, + .categoryHotel: + path = "search/v1/category/\(endpoint.rawValue)" case .multiRetrieve: break diff --git a/Tests/MapboxSearchUITests/MockWebServer/category-hotel-search-along-route-jp.json b/Tests/MapboxSearchUITests/MockWebServer/category-hotel-search-along-route-jp.json new file mode 100644 index 000000000..a570f0348 --- /dev/null +++ b/Tests/MapboxSearchUITests/MockWebServer/category-hotel-search-along-route-jp.json @@ -0,0 +1,687 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.73952222241294, + 35.664124999576146 + ], + "type": "Point" + }, + "properties": { + "feature_name": "ホテルヴィラフォンテーヌグランド東京六本木", + "matching_name": "ホテルヴィラフォンテーヌグランド東京六本木", + "highlighted_name": "ホテルヴィラフォンテーヌグランド東京六本木", + "description": "東京都港区六本木1-6-2", + "place_name": "ホテルヴィラフォンテーヌグランド東京六本木, 東京都港区六本木1-6-2", + "id": "dXJuOm1ieHBvaS1qcG46NTdjYzExMWUzZTQ0NDYzOTczY2NkZTgwZmI4NWYyYTI4ZTYxYmYyNjQ0Y2MzZmU0N2Q0NDU0ZmIzM2ExNjlhNw", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木1-6-2" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木1-6-2" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "港区" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.PcG5CQAgDABA57GQxI9sIwEtRE2R0ukVBO-seXYT7VImS12sw2HwgPeHiXyGCHQA", + "external_ids": { + "zenrin_landmark": "13201010000000000158260408", + "mbx_poi": "dXJuOm1ieHBvaS1qcG46NTdjYzExMWUzZTQ0NDYzOTczY2NkZTgwZmI4NWYyYTI4ZTYxYmYyNjQ0Y2MzZmU0N2Q0NDU0ZmIzM2ExNjlhNw" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73991944419012, + 35.66394444465637 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.739588, + 35.66448 + ], + "type": "Point" + }, + "properties": { + "feature_name": "ヴィラフォンテーヌ六本木", + "matching_name": "ヴィラフォンテーヌ六本木", + "highlighted_name": "ヴィラフォンテーヌ六本木", + "description": "東京都港区六本木1-6-2", + "place_name": "ヴィラフォンテーヌ六本木, 東京都港区六本木1-6-2", + "id": "dXJuOm1ieHBvaS1qcG46OTBmNDBmOGZmZWI4Mzg2MmMzNjI3ZjJhZWFiODVhYmQ3MDg4ZTk3NmY4YzI2MjMzN2JlMGY3NzA4MDAzYzk0Nw", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木1-6-2" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木1-6-2" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "港区" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolS95DRTCzNjU8Mk89REE2NjI8tEoIBRUhoA", + "external_ids": { + "foursquare": "cf586351b7ea43329af582bf", + "mbx_poi": "dXJuOm1ieHBvaS1qcG46OTBmNDBmOGZmZWI4Mzg2MmMzNjI3ZjJhZWFiODVhYmQ3MDg4ZTk3NmY4YzI2MjMzN2JlMGY3NzA4MDAzYzk0Nw" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.7399993461539, + 35.66439773076928 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.738233, + 35.663812 + ], + "type": "Point" + }, + "properties": { + "feature_name": "朝日六本木マンション", + "matching_name": "朝日六本木マンション", + "highlighted_name": "朝日六本木マンション", + "description": "東京都港区六本木3-2-19", + "place_name": "朝日六本木マンション, 東京都港区六本木3-2-19", + "id": "dXJuOm1ieHBvaS1qcG46NTJkYTI1ZDgxMDAzMDQzMTYzMThlOTNjYjM5MjljNTI2NTExYWFiZTk1YWNiNzY5NGQ0OGI2ODgzMzBmNzQ2Yg", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木3-2-19" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木3-2-19" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "港区" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ9c1Mzk7Q0y2SzFBMjE8NkC6OUJDNLk-RkAA==", + "external_ids": { + "foursquare": "7564ff9c6d4241c82db694cc", + "mbx_poi": "dXJuOm1ieHBvaS1qcG46NTJkYTI1ZDgxMDAzMDQzMTYzMThlOTNjYjM5MjljNTI2NTExYWFiZTk1YWNiNzY5NGQ0OGI2ODgzMzBmNzQ2Yg" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73824858754253, + 35.66371691599058 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.738795, + 35.664395 + ], + "type": "Point" + }, + "properties": { + "feature_name": "ホテルヴィラフォンテーヌ六本木", + "matching_name": "ホテルヴィラフォンテーヌ六本木", + "highlighted_name": "ホテルヴィラフォンテーヌ六本木", + "description": "東京都港区六本木1-6-2", + "place_name": "ホテルヴィラフォンテーヌ六本木, 東京都港区六本木1-6-2", + "id": "dXJuOm1ieHBvaS1qcG46YTRjOTFlNzQwZmI5MDZkYzRhNjM2MDZkM2M3OWEyNmExNWQ0NTg3NGQ1MTE2M2JjODc1MDUxNjNmOGNkMjgxNg", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木1-6-2" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木1-6-2" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "港区" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ9k6RUUxOjNGMjE1PzRFNLY-NkE_PEJENTAA==", + "external_ids": { + "mbx_poi": "dXJuOm1ieHBvaS1qcG46YTRjOTFlNzQwZmI5MDZkYzRhNjM2MDZkM2M3OWEyNmExNWQ0NTg3NGQ1MTE2M2JjODc1MDUxNjNmOGNkMjgxNg", + "foursquare": "4be542f32457a5933c47ab15" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73879371353684, + 35.664395357647436 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.737644, + 35.664943 + ], + "type": "Point" + }, + "properties": { + "feature_name": "ヴィラフォンテーヌ六本木ANNEX", + "matching_name": "ヴィラフォンテーヌ六本木ANNEX", + "highlighted_name": "ヴィラフォンテーヌ六本木ANNEX", + "description": "東京都港区六本木3-2-7", + "place_name": "ヴィラフォンテーヌ六本木ANNEX, 東京都港区六本木3-2-7", + "id": "dXJuOm1ieHBvaS1qcG46MWNiMWMzZmQwM2IzNDY5MGIwYzc2NjY3MjY0ZTkxZWY1ZjQyNmMxMDI3ZTgwYTAzNjUyOWM4M2Y4NzQ5YTQwMg", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木3-2-7" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木3-2-7" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "東京都" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ94zRLi1TzpETTRIs0k2TDVGNzM5PUtERTAA==", + "external_ids": { + "foursquare": "3f98e7ba5a8f4c1e3764efa5", + "mbx_poi": "dXJuOm1ieHBvaS1qcG46MWNiMWMzZmQwM2IzNDY5MGIwYzc2NjY3MjY0ZTkxZWY1ZjQyNmMxMDI3ZTgwYTAzNjUyOWM4M2Y4NzQ5YTQwMg" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.7376750605189, + 35.66520018109675 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.737505, + 35.66491 + ], + "type": "Point" + }, + "properties": { + "feature_name": "六本木アネックス", + "matching_name": "六本木アネックス", + "highlighted_name": "六本木アネックス", + "description": "東京都港区六本木3-13-3", + "place_name": "六本木アネックス, 東京都港区六本木3-13-3", + "id": "dXJuOm1ieHBvaS1qcG46ZDZkMWE0NmQzMDZkNDFkMmZmNjJjMjY1OTRlZTllZTAxMzUyMzdjOTU3MWJhM2ZmOTUyYjYxNjVjNjRhODRhZg", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木3-13-3" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木3-13-3" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "東京都" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ9kxRDU0vjZAMj0-SUREMTY-OUJCOzxBQzAA==", + "external_ids": { + "mbx_poi": "dXJuOm1ieHBvaS1qcG46ZDZkMWE0NmQzMDZkNDFkMmZmNjJjMjY1OTRlZTllZTAxMzUyMzdjOTU3MWJhM2ZmOTUyYjYxNjVjNjRhODRhZg", + "foursquare": "4d1593c025cda1433db26ad6" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73754198704972, + 35.66521625277177 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.7374694445398, + 35.6616999997033 + ], + "type": "Point" + }, + "properties": { + "feature_name": "アパホテル&リゾート六本木駅東", + "matching_name": "アパホテル&リゾート六本木駅東", + "highlighted_name": "アパホテル&リゾート六本木駅東", + "description": "東京都港区六本木3-18-6", + "place_name": "アパホテル&リゾート六本木駅東, 東京都港区六本木3-18-6", + "id": "dXJuOm1ieHBvaS1qcG46ZTg3ODMxMjI4NTZkMzIyNzQ5YjUzZGQxMTRmYzU1OGFiYWMxZGE5N2JlNTllNjIwZmU2NDM3M2EyY2YxMjRlMA", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木3-18-6" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木3-18-6" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "東京都" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.LcAxDgAQDABA_5FItQSvkSYMgg4dvd7AWfOcLjqkLpa2WafzhOAB4SPIKVLJGFK5", + "external_ids": { + "mbx_poi": "dXJuOm1ieHBvaS1qcG46ZTg3ODMxMjI4NTZkMzIyNzQ5YjUzZGQxMTRmYzU1OGFiYWMxZGE5N2JlNTllNjIwZmU2NDM3M2EyY2YxMjRlMA", + "zenrin_landmark": "132010200000000308753982479" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73765833324856, + 35.66126111136542 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.73579722219043, + 35.66213611072964 + ], + "type": "Point" + }, + "properties": { + "feature_name": "三井ガーデンホテル六本木プレミア", + "matching_name": "三井ガーデンホテル六本木プレミア", + "highlighted_name": "三井ガーデンホテル六本木プレミア", + "description": "東京都港区六本木3-15-17", + "place_name": "三井ガーデンホテル六本木プレミア, 東京都港区六本木3-15-17", + "id": "dXJuOm1ieHBvaS1qcG46MzFkYWQ3MGQ3YWRiNWRiMDhhYjU2MmZkYzQyZmJhYzM3ZWQ3YzY5ZjQ4MWYwNTEwMTdiMWY0OWFiOGExN2QzMg", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木3-15-17" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "六本木3-15-17" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "東京都" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ901TDtFSTRCPTRGNDU2MDAwOL1OREQyMTAA==", + "external_ids": { + "zenrin_landmark": "132010100000000005763689853", + "mbx_poi": "dXJuOm1ieHBvaS1qcG46MzFkYWQ3MGQ3YWRiNWRiMDhhYjU2MmZkYzQyZmJhYzM3ZWQ3YzY5ZjQ4MWYwNTEwMTdiMWY0OWFiOGExN2QzMg", + "foursquare": "5e1fe4a25a31530008eca124" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73587222231757, + 35.66180555555555 + ] + } + ] + } + }, + { + "type": "Feature", + "geometry": { + "coordinates": [ + 139.737397222254, + 35.666294444402055 + ], + "type": "Point" + }, + "properties": { + "feature_name": "アパホテル六本木SIX", + "matching_name": "アパホテル六本木SIX", + "highlighted_name": "アパホテル六本木SIX", + "description": "東京都港区六本木2-3-11", + "place_name": "アパホテル六本木SIX, 東京都港区六本木2-3-11", + "id": "dXJuOm1ieHBvaS1qcG46YTJmMGRhOTk4MmE5MTRmY2ExMTdlNjE4MjQ3YzkxMDA2NDczNGUzY2M1ZjM3NDU4YmQ3ZjMzNDNhMTgzMjYwNQ", + "place_type": [ + "poi" + ], + "context": [ + { + "layer": "address", + "localized_layer": "address", + "name": "東京都港区六本木2-3-11" + }, + { + "layer": "street", + "localized_layer": "street", + "name": "" + }, + { + "layer": "postcode", + "localized_layer": "postcode", + "name": "106-0032" + }, + { + "layer": "place", + "localized_layer": "place", + "name": "東京都" + }, + { + "layer": "region", + "localized_layer": "region", + "name": "東京都" + } + ], + "maki": "lodging", + "poi_category": [ + "トラベル>ホテル", + "トラベル", + "トラベル>民宿" + ], + "poi_category_ids": [ + "トラベル>ホテル", + "トラベル", + "トラベル>民宿" + ], + "internal_id": "Y2aAgIL8TAA=.42eAgMSCTN2C_Ezd4tSisszkVAA=.U2aAgLT80qLiwtLEolQ9k9TkRNNUc8s0c0sDE0NjUyMDg5Qk42QzAA==", + "external_ids": { + "mbx_poi": "dXJuOm1ieHBvaS1qcG46YTJmMGRhOTk4MmE5MTRmY2ExMTdlNjE4MjQ3YzkxMDA2NDczNGUzY2M1ZjM3NDU4YmQ3ZjMzNDNhMTgzMjYwNQ", + "foursquare": "4eca5e79f7904135200db3c6", + "zenrin_landmark": "132010200000000308073739182" + }, + "metadata": { + "iso_3166_1": "JP", + "iso_3166_2": "JP-13" + }, + "routable_points": [ + { + "name": "POI", + "coordinates": [ + 139.73753055546018, + 35.66614166683621 + ] + } + ] + } + } + ], + "attribution": "© 2023 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/)", + "version": "272:8f01e9d5fbb40d5c3596666f5f9e76f10d82d12b", + "response_uuid": "9bd717ca-da98-45e1-a292-b2348303c670" +} From 44907d7e1d1ffa8b22a6901f0709a25f5a0e5137 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Thu, 8 Feb 2024 11:51:46 -0500 Subject: [PATCH 3/7] Fix category tests (until more advanced test fixes in other PRs can be merged) - SSDK-399 --- .../CategorySearchEngineIntegrationTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift index 2b58448e8..1ae1d8a36 100644 --- a/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/CategorySearchEngineIntegrationTests.swift @@ -13,7 +13,7 @@ class CategorySearchEngineIntegrationTests: MockServerTestCase { try server.setResponse(.categoryCafe) let expectation = XCTestExpectation(description: "Expecting results") - searchEngine.search(categoryName: "ATM") { result in + searchEngine.search(categoryName: "cafe") { result in switch result { case .success(let searchResults): XCTAssertFalse(searchResults.isEmpty) @@ -30,7 +30,7 @@ class CategorySearchEngineIntegrationTests: MockServerTestCase { try server.setResponse(.categoryCafe, statusCode: 500) let expectation = XCTestExpectation(description: "Expecting failure") - searchEngine.search(categoryName: "ATM") { result in + searchEngine.search(categoryName: "cafe") { result in switch result { case .success: XCTFail("Not expected") From 90f8abb99a551bdbc06ad97164393d880ce55abf Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 10:12:44 -0500 Subject: [PATCH 4/7] Remove Discover.Options.country nil to .default assignment - SSDK-399 - Add docs for origin and proximity --- .../Discover API/Models/Discover+Options.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift index 6721ee480..fec0f11b1 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Models/Discover+Options.swift @@ -16,12 +16,16 @@ extension Discover { public let language: Language /// See ``MapboxSearch.Country.ISO3166_1_alpha2`` for the list of ISO 3166 alpha 2 country codes. - /// The default value will be selected from the Country.ISO3166\_1\_alpha2 identifiers based on the current - /// locale identifier or nil if no match is found. + /// The default value is nil. public let country: Country? + /// Bias the response to favor results that are closer to a specific location. + /// When both proximity and origin are provided, origin is interpreted as the target of a route, while proximity + /// indicates the current user location. public let proximity: CLLocationCoordinate2D? + /// The location from which to calculate distance. When both proximity and origin are provided, origin is + /// interpreted as the target of a route, while proximity indicates the current user location. public let origin: CLLocationCoordinate2D? public init( @@ -33,7 +37,7 @@ extension Discover { ) { self.limit = limit self.language = language ?? .default - self.country = country ?? .default + self.country = country self.proximity = proximity self.origin = origin } From 757a6b145409a86feab3062a98b0f9834e022235 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 10:49:00 -0500 Subject: [PATCH 5/7] Fix propagation of Discover.Options.proximity to SearchOptions.proximity - SSDK-399 --- .../PublicAPI/Use Cases/Discover API/Discover.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift index 7a1f9d672..e900ec74c 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift @@ -62,7 +62,7 @@ extension Discover { countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, - proximity: proximity, + proximity: options.proximity ?? proximity, origin: options.origin ) @@ -90,7 +90,7 @@ extension Discover { countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, - proximity: proximity, + proximity: proximity ?? options.proximity, boundingBox: region, origin: options.origin ) From 4f17c4cd90d8e89f4eb74105fae5377954d7093d Mon Sep 17 00:00:00 2001 From: Jack Alto <384288+aokj4ck@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:04:10 -0500 Subject: [PATCH 6/7] Update Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift Co-authored-by: Nastassia Makaranka --- .../PublicAPI/Use Cases/Discover API/Discover.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift index e900ec74c..f6e857675 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift @@ -62,7 +62,7 @@ extension Discover { countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, - proximity: options.proximity ?? proximity, + proximity: proximity origin: options.origin ) From 597d94684ab705c800c493a0e678e812622b8df6 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 14 Feb 2024 11:22:12 -0500 Subject: [PATCH 7/7] Fix build issue --- .../PublicAPI/Use Cases/Discover API/Discover.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift index f6e857675..c2f570cc3 100644 --- a/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift +++ b/Sources/MapboxSearch/PublicAPI/Use Cases/Discover API/Discover.swift @@ -62,7 +62,7 @@ extension Discover { countries: [options.country?.countryCode].compactMap { $0 }, languages: [options.language.languageCode], limit: options.limit, - proximity: proximity + proximity: proximity, origin: options.origin )