Page updated Jan 16, 2024

Use Amazon Location Service SDK

If you need functionality in the AWS services used by the Amplify Geo category that isn't available, we provide an escape hatch so you can get a reference to that service.

Note: If you provisioned your Geo resources via Amplify CLI, then the IAM policy will be specifically scoped to only allow actions required by the library. Please adjust your authorization permissions accordingly for your escape hatch use-cases.

Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures here.

1import android.util.Log;
2
3import androidx.annotation.NonNull;
4
5import com.amplifyframework.core.Amplify;
6import com.amplifyframework.geo.location.AWSLocationGeoPlugin;
7
8import aws.sdk.kotlin.services.location.LocationClient;
9import aws.sdk.kotlin.services.location.model.ListMapsRequest;
10import aws.sdk.kotlin.services.location.model.ListMapsResponse;
11import kotlin.Unit;
12import kotlin.coroutines.Continuation;
13import kotlin.coroutines.CoroutineContext;
14import kotlinx.coroutines.GlobalScope;
1// Obtain reference to the plugin
2AWSLocationGeoPlugin geoPlugin = (AWSLocationGeoPlugin)
3 Amplify.Geo.getPlugin("awsLocationGeoPlugin");
4LocationClient locationClient = geoPlugin.getEscapeHatch();
5
6// Send a new request to the Location Maps endpoint directly using the client
7ListMapsRequest request = ListMapsRequest.Companion.invoke(requestBuilder -> Unit.INSTANCE);
8locationClient.listMaps(request, new Continuation<ListMapsResponse>() {
9 @NonNull
10 @Override
11 public CoroutineContext getContext() {
12 return GlobalScope.INSTANCE.getCoroutineContext();
13 }
14
15 @Override
16 public void resumeWith(@NonNull Object resultOrException) {
17 Log.i("MyAmplifyApp", resultOrException.toString());
18 }
19});
1import android.util.Log
2import aws.sdk.kotlin.services.location.LocationClient
3import aws.sdk.kotlin.services.location.model.ListMapsRequest
4import com.amplifyframework.core.Amplify
1// Obtain reference to the Amazon Location Service client
2val geoPlugin = Amplify.Geo.getPlugin("awsLocationGeoPlugin")
3val locationClient = geoPlugin.escapeHatch as LocationClient
4
5// Send a new request to the Location Maps endpoint directly using the client
6val request = ListMapsRequest { }
7val response = locationClient.listMaps(request)
8Log.i("MyAmplifyApp", response.entries.toString())

Documentation Resources

Maps

Places

Device Tracking