From 6a3a3bd6423c27f1e17f6e9b062cef0ac5baac23 Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Fri, 10 May 2024 15:53:38 -0400 Subject: [PATCH 1/3] fix(Swift): Addressing some gaps in Geo Gen2 doc pages --- .../geo/configure-location-search/index.mdx | 1 + .../geo/location-search/index.mdx | 26 ++++++++--------- .../add-aws-services/geo/maps/index.mdx | 26 ----------------- .../add-aws-services/geo/set-up-geo/index.mdx | 28 ++++++++++++------- 4 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx index 2bbd2bb8a31..07de8130d38 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx @@ -86,6 +86,7 @@ backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPoli // patch the place index resource to the expected output configuration backend.addOutput({ geo: { + aws_region: geoStack.region, search_indices: { default: myIndex.indexName, items: [myIndex.indexName], diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/location-search/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/location-search/index.mdx index 31b9d41fc17..770e380bb0e 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/location-search/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/location-search/index.mdx @@ -391,19 +391,19 @@ You can customize the feature images displayed on the `AMLMapView` or `AMLMapCom {/* // spell-checker: disable */} ```swift - var body: some View { - AMLMapView(mapState: mapState) - .featureImage { - let image = UIImage( - systemName: "paperplane.circle.fill", - withConfiguration: UIImage.SymbolConfiguration( - font: .systemFont(ofSize: 22, weight: .medium) - ) - )! - return image - } - .edgesIgnoringSafeArea(.all) - } +var body: some View { + AMLMapView(mapState: mapState) + .featureImage { + let image = UIImage( + systemName: "paperplane.circle.fill", + withConfiguration: UIImage.SymbolConfiguration( + font: .systemFont(ofSize: 22, weight: .medium) + ) + )! + return image + } + .edgesIgnoringSafeArea(.all) +} ``` {/* // spell-checker: enable */} diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx index 70ac8e38445..29a927e3faf 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx @@ -902,30 +902,6 @@ struct ContentView: View { - - - -```swift -import AmplifyMapLibreAdapter -import Mapbox -import Amplify - -var mapView: MGLMapView? - -AmplifyMapLibre.createMap { result in - switch result { - case .failure(let error): - print(error) - case .success(let map): - mapView = map - } -} -``` - - - - - ```swift import AmplifyMapLibreAdapter import Mapbox @@ -938,8 +914,6 @@ do { print(error) } ``` - - diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx index c6dc7558f67..088f5a821fb 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx @@ -209,21 +209,18 @@ dependencies { The Geo plugin is dependent on Cognito Auth. - - - +1. To install the Amplify Libraries in your application, open your project in Xcode and select **File > Add Packages...**. -1. To install Amplify Geo and Authentication to your application, open your project in Xcode and select **File > Add Packages...**. +2. Enter the **Amplify Library for Swift** GitHub repo URL (`https://github.com/aws-amplify/amplify-swift`) into the search bar and click **Add Package**. -1. Enter the **Amplify Library for Swift** GitHub repo URL (`https://github.com/aws-amplify/amplify-swift`) into the search bar and and hit **Enter** Wait for the result to load. You'll see the repository rules for which version of amplify-ios-mapLibre you want Swift Package Manager to install. + -1. Choose the dependency rule **Up to Next Major Version**, as it will use the latest compatible version of the dependency, then click **Add Package**. + **Note:** **Up to Next Major Version** should be selected from the **Dependency Rule** dropdown. -1. Lastly, choose **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify**. Then click Finish. + - +1. Lastly, add **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify** to your target. Then click **Add Package**. - ## Initialize Amplify Geo @@ -340,12 +337,23 @@ Initialized Amplify -To initialize the Amplify Geo, use the `Amplify.addPlugin()` method to add the AWSLocationGeoPlugin. Next, finish configuring Amplify by calling `Amplify.configure()`. + +Make sure to generate the `amplify_outputs.json` file by running the following command: + +```bash title="Terminal" showLineNumbers={false} +npx ampx sandbox +``` + +Next, move the file to your project. You can do this by dragging and dropping the file into your Xcode project. + + +To initialize Amplify Geo, use the `Amplify.add(plugin:)` method to add the AWS Location Geo plugin. Next, finish configuring Amplify by calling `Amplify.configure(with:)`. Open the main file of the application - `AppDelegate.swift` or `App.swift` depending on the app's life cycle - and **add the following** import statements at the top of the file: ```swift import Amplify +import AWSCognitoAuthPlugin import AWSLocationGeoPlugin ``` From 628cc71f85db1af7e71bbf465a19609a264d2a0d Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Fri, 10 May 2024 17:06:12 -0400 Subject: [PATCH 2/3] chore: Adding missing section to backend.ts file --- .../geo/configure-location-search/index.mdx | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx index 07de8130d38..6ab7f120493 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx @@ -35,7 +35,8 @@ Amplify's `geo` category enables you to search by places, addresses, and coordin ```ts title="amplify/backend.ts" import { defineBackend } from "@aws-amplify/backend"; import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; -import { CfnPlaceIndex } from "aws-cdk-lib/aws-location"; +// highlight-next-line +import { CfnMap, CfnPlaceIndex } from "aws-cdk-lib/aws-location"; import { auth } from "./auth/resource"; import { data } from "./data/resource"; @@ -47,6 +48,44 @@ const backend = defineBackend({ const geoStack = backend.createStack("geo-stack"); +// create a location services map +const map = new CfnMap(geoStack, "Map", { + mapName: "myMap", + description: "Map", + configuration: { + style: "VectorEsriNavigation", + }, + pricingPlan: "RequestBasedUsage", + tags: [ + { + key: "name", + value: "myMap", + }, + ], +}); + + +// create an IAM policy to allow interacting with geo resource +const myGeoPolicy = new Policy(geoStack, "GeoPolicy", { + policyName: "myGeoPolicy", + statements: [ + new PolicyStatement({ + actions: [ + "geo:GetMapTile", + "geo:GetMapSprites", + "geo:GetMapGlyphs", + "geo:GetMapStyleDescriptor", + ], + resources: [map.attrArn], + }), + ], +}); + +// apply the policy to the authenticated and unauthenticated roles +backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy); +backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy); + +// highlight-start // create a location services place index const myIndex = new CfnPlaceIndex(geoStack, "PlaceIndex", { dataSource: "Here", @@ -82,15 +121,26 @@ const myIndexPolicy = new Policy(geoStack, "IndexPolicy", { // attach the policy to the authenticated and unauthenticated IAM roles backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy); backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy); +// highlight-end // patch the place index resource to the expected output configuration backend.addOutput({ geo: { aws_region: geoStack.region, + maps: { + items: { + [map.mapName]: { + style: "VectorEsriNavigation", + }, + }, + default: map.mapName, + }, +// highlight-start search_indices: { default: myIndex.indexName, items: [myIndex.indexName], }, +// highlight-end }, }); ``` From 89e64c0fa0a1d5d3c68212dd3ba7cc6c112027a9 Mon Sep 17 00:00:00 2001 From: Sebastian Villena <97059974+ruisebas@users.noreply.github.com> Date: Mon, 13 May 2024 13:03:44 -0400 Subject: [PATCH 3/3] Update src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx Co-authored-by: josef --- .../build-a-backend/add-aws-services/geo/set-up-geo/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx index 088f5a821fb..3cb76c85cf4 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx @@ -219,7 +219,7 @@ The Geo plugin is dependent on Cognito Auth. -1. Lastly, add **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify** to your target. Then click **Add Package**. +3. Lastly, add **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify** to your target. Then click **Add Package**.