Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Set up Amplify Geo

Amplify Geo provides APIs and map UI components for mobile app development such that you can add maps to your app in just a few lines of code. Amplify Geo APIs are powered by Amazon Location Service and the map UI components from MapLibre are already integrated with the Geo APIs. You can quickly get started using Amplify CLI to provision your map resources.

Follow this guide to get started with Amplify Geo through the Amplify CLI.

Note:

  • If you want to use existing Amazon Location Service resources follow this guide instead.
  • If you want to use Amazon Location Service APIs not directly supported by Geo, use the escape hatch to access the Amazon Location Service SDK.

Prerequisites

An application with Amplify libraries integrated and a minimum target of any of the following:

  • iOS 13.0, using Xcode 14.1 or later.
  • macOS 10.15, using Xcode 14.1 or later.
  • tvOS 13.0, using Xcode 14.3 or later.
  • watchOS 9.0, using Xcode 14.3 or later.
  • visionOS 1.0, using Xcode 15 or later. (Preview support - see below for more details.)

For a full example, please follow the project setup walkthrough.

visionOS support is currently in preview and can be used by using the latest Amplify Release. As new Xcode and visionOS versions are released, the support will be updated with any necessary fixes on a best effort basis.

Provisioning resources through CLI

Prerequisite: Install and configure the Amplify CLI

To start provisioning Geo resources in the backend, go to your project directory and execute the command:

amplify add geo

The CLI will prompt configuration options for the Geo category for what type of capability you want to add and default or advanced settings. The add command automatically creates the backend configuration. Once all your configuration is complete run the following:

amplify push

Upon completion, amplifyconfiguration.json should be updated to reference provisioned backend geo resources. Note that this file should already be a part of your project if you followed the Project setup walkthrough.

Install Amplify Libraries

The Geo plugin is dependent on Cognito Auth.

Swift Package Manager

  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 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.

  3. Choose the dependency rule Up to Next Major Version, as it will use the latest compatible version of the dependency, then click Add Package.

  4. Lastly, choose AWSLocationGeoPlugin, AWSCognitoAuthPlugin, and Amplify. Then click Finish.

Initialize Amplify Geo

To initialize the Amplify Geo, use the Amplify.addPlugin() method to add the AWSLocationGeoPlugin. Next, finish configuring Amplify by calling Amplify.configure().

Open the main file of the application - AppDelegate.swift or <YOUR_APP_NAME>App.swift depending on the app's life cycle - and add the following import statements at the top of the file:

import Amplify
import AWSLocationGeoPlugin

In the same file, create a function to configure Amplify:

func configureAmplify() {
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.add(plugin: AWSLocationGeoPlugin())
try Amplify.configure()
print("Initialized Amplify");
} catch {
print("Could not initialize Amplify: \(error)")
}
}

Now call the configureAmplify() function in the starting point of your application.

@main
struct <YOUR_APP_NAME>App: App {
// add a default initializer and configure Amplify
public init() {
configureAmplify()
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
configureAmplify()
return true
}
// ...
}

Upon building and running this application you should see the following in your console window:

Initialized Amplify