Aller au contenu principal

Geolocation

The Geolocation Block is used to handle the geolocation services in the app by providing access to the user's location and provide the ability to search show it on a map.

Set Up

The geolocation service runs the Google Maps API in background. This means that an API key must be obtained on the Google Cloud Platform and added to the project. This requires some platform specific setup.

iOS

For iOS you'll have to modify three files, the AppDelegate.swift, the Info.plist and the Podfile.

In the Info.plist file, add the following :

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>

Add the Google Maps API key in ios/Runner/AppDelegate.swift file.

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR_KEY")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

In the Podfile update the platform version to 14.0.

platform :ios, '14.0'

Android

For Android you'll have to modify the AndroidManifest.xml and the build.gradle files.

In the android/app/build.gradle file, uipdate the compiled SDK version to at least 33:

android {
compileSdkVersion 33
...
}

In the android/app/src/main/AndroidManifest.xml file, add the following permissions and the Google Maps API key.

<manifest ...>
...
<!-- CODIKA_ADDED_GEOLOCATION -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
...
<application ...>
...
<!-- CODIKA_ADDED_GEOLOCATION -->
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_KEY"/>
<activity ...>
...
</activity>
</application>
</manifest>

How Does It Work?

Widgets

Cloud Functions

Services

Upgrader