# Google Maps

Canonical HTML: https://p-hatan.com/deeplink-x/apps/google-maps/

DeeplinkX 1.5.8.

## Platforms and setup

Native platforms: **ios, android**.



## Public actions

### GoogleMaps.open


```dart
factory GoogleMaps.open({final bool fallbackToStore = false})
```

Launch with `DeeplinkX.launchApp`. Native platforms: **ios, android**. Action web fallback: **available**. Store-fallback flag: **supported; opt in explicitly**.

| Parameter | Type | Required | Default |
| --- | --- | --- | --- |
| `fallbackToStore` | `bool` | No | `false` |

[Exact source](https://github.com/DeepLinkX/DeeplinkX/blob/00d9d2c7c1affe4e2ee459a01afeba82a1480eac/lib/src/apps/downloadable_apps/google_maps.dart#L22)

### GoogleMaps.view


```dart
static GoogleMapsViewAction view({ required final Coordinate coordinate, final double? zoom, final bool fallbackToStore = false, })
```

Launch with `DeeplinkX.launchAction`. Native platforms: **ios, android**. Action web fallback: **available**. Store-fallback flag: **supported; opt in explicitly**.

| Parameter | Type | Required | Default |
| --- | --- | --- | --- |
| `coordinate` | `Coordinate` | Yes | — |
| `zoom` | `double?` | No | — |
| `fallbackToStore` | `bool` | No | `false` |

[Exact source](https://github.com/DeepLinkX/DeeplinkX/blob/00d9d2c7c1affe4e2ee459a01afeba82a1480eac/lib/src/apps/downloadable_apps/google_maps.dart#L65)

### GoogleMaps.search


```dart
static GoogleMapsSearchAction search({ required final String query, final bool fallbackToStore = false, })
```

Launch with `DeeplinkX.launchAction`. Native platforms: **ios, android**. Action web fallback: **available**. Store-fallback flag: **supported; opt in explicitly**.

| Parameter | Type | Required | Default |
| --- | --- | --- | --- |
| `query` | `String` | Yes | — |
| `fallbackToStore` | `bool` | No | `false` |

[Exact source](https://github.com/DeepLinkX/DeeplinkX/blob/00d9d2c7c1affe4e2ee459a01afeba82a1480eac/lib/src/apps/downloadable_apps/google_maps.dart#L85)

### GoogleMaps.directions


```dart
static GoogleMapsDirectionsAction directions({ required final String destination, final String? origin, final GoogleMapsTravelMode? mode, final bool fallbackToStore = false, })
```

Launch with `DeeplinkX.launchAction`. Native platforms: **ios, android**. Action web fallback: **available**. Store-fallback flag: **supported; opt in explicitly**.

| Parameter | Type | Required | Default |
| --- | --- | --- | --- |
| `destination` | `String` | Yes | — |
| `origin` | `String?` | No | — |
| `mode` | `GoogleMapsTravelMode?` | No | — |
| `fallbackToStore` | `bool` | No | `false` |

[Exact source](https://github.com/DeepLinkX/DeeplinkX/blob/00d9d2c7c1affe4e2ee459a01afeba82a1480eac/lib/src/apps/downloadable_apps/google_maps.dart#L105)

### GoogleMaps.directionsWithCoords


```dart
static GoogleMapsDirectionsWithCoordsAction directionsWithCoords({ required final Coordinate destination, final Coordinate? origin, final GoogleMapsTravelMode? mode, final bool fallbackToStore = false, })
```

Launch with `DeeplinkX.launchAction`. Native platforms: **ios, android**. Action web fallback: **available**. Store-fallback flag: **supported; opt in explicitly**.

| Parameter | Type | Required | Default |
| --- | --- | --- | --- |
| `destination` | `Coordinate` | Yes | — |
| `origin` | `Coordinate?` | No | — |
| `mode` | `GoogleMapsTravelMode?` | No | — |
| `fallbackToStore` | `bool` | No | `false` |

[Exact source](https://github.com/DeepLinkX/DeeplinkX/blob/00d9d2c7c1affe4e2ee459a01afeba82a1480eac/lib/src/apps/downloadable_apps/google_maps.dart#L129)


## Provider setup and examples
DeeplinkX provides support for Google Maps deep linking actions on iOS and Android.

## References

- [Android Intents](https://developer.android.com/guide/components/google-maps-intents)
- [iOS URL Scheme](https://developers.google.com/maps/documentation/urls/ios-urlscheme)
- [Google Maps URLs](https://developers.google.com/maps/documentation/urls/get-started)

## Available Actions

### Launch Google Maps App
```dart
final deeplinkX = DeeplinkX();
await deeplinkX.launchApp(GoogleMaps.open());
```

### View Map Action
```dart
await deeplinkX.launchAction(
  GoogleMaps.view(
    coordinate: const Coordinate(latitude: 37.4220, longitude: -122.0841),
    zoom: 14,
  ),
);
```

### Search Location Action
```dart
await deeplinkX.launchAction(
  GoogleMaps.search(query: 'Central Park, New York'),
);
```

### Directions Action
```dart
await deeplinkX.launchAction(
  GoogleMaps.directions(
    origin: 'Times Square, New York',
    destination: 'Statue of Liberty',
    mode: GoogleMapsTravelMode.transit,
  ),
);
```

### Directions with Coordinates Action
```dart
await deeplinkX.launchAction(
  GoogleMaps.directionsWithCoords(
    origin: const Coordinate(latitude: 40.7580, longitude: -73.9855),
    destination: const Coordinate(latitude: 40.6892, longitude: -74.0445),
    mode: GoogleMapsTravelMode.walking,
  ),
);
```

## Platform Configuration

### iOS
Add the following to your `ios/Runner/Info.plist` inside the `LSApplicationQueriesSchemes` array:
```xml
<string>comgooglemaps</string>
```

### Android
Add the following to your `android/app/src/main/AndroidManifest.xml` inside the `<queries>` tag:
```xml
<package android:name="com.google.android.apps.maps" />
```

## URL Schemes

### Native App Deep Links
- View map: `comgooglemaps://?center={lat},{lng}&zoom={zoom}`
- Search: `comgooglemaps://?q={query}`
- Directions: `comgooglemaps://?saddr={origin}&daddr={destination}&directionsmode={mode}`
- Directions with coordinates: `comgooglemaps://?saddr={origin_lat},{origin_lng}&daddr={dest_lat},{dest_lng}&directionsmode={mode}`

### Android Intent URIs
- View map: `geo:{lat},{lng}?z={zoom}`
- Search: `geo:0,0?q={query}`
- Directions: `https://www.google.com/maps/dir/?api=1&destination={destination}&origin={origin}&travelmode={mode}`
- Directions with coordinates: `https://www.google.com/maps/dir/?api=1&destination={dest_lat},{dest_lng}&origin={origin_lat},{origin_lng}&travelmode={mode}`

### Web Fallback URLs
- View map: `https://www.google.com/maps/@?api=1&map_action=map&center={lat},{lng}&zoom={zoom}`
- Search: `https://www.google.com/maps/search/?api=1&query={query}`
- Directions: `https://www.google.com/maps/dir/?api=1&destination={destination}&origin={origin}&travelmode={mode}`
- Directions with coordinates: `https://www.google.com/maps/dir/?api=1&destination={dest_lat},{dest_lng}&origin={origin_lat},{origin_lng}&travelmode={mode}`
- Directions from current location: `https://www.google.com/maps/dir/?api=1&destination=40.6892,-74.0445`

Google requires `api=1` on Maps URLs. Without it, the documented action parameters can be ignored. Coordinate destinations use latitude,longitude order; when `origin` is omitted, Google Maps starts from the user's current location.

## Supported Fallback Stores
When the Google Maps app is not installed, DeeplinkX can redirect users to download Google Maps from:

- iOS App Store
- Google Play Store

Enable fallback with the `fallbackToStore` parameter when launching actions or apps.

## Fallback Behavior

1. Attempt to launch the Google Maps app if installed.
2. If not installed and `fallbackToStore` is `true`, redirect to the appropriate app store.
3. If the store cannot be opened, fall back to opening the Google Maps website.
4. Disable all fallbacks by setting `disableFallback: true`.

## Fallback Support for Actions

| Action                     | Store Fallback | Web Fallback |
| -------------------------- | -------------- | ------------ |
| Open app                   | ✔️ | ✔️ |
| View map                   | ✔️ | ✔️ |
| Search                     | ✔️ | ✔️ |
| Directions                 | ✔️ | ✔️ |
| Directions with coordinates| ✔️ | ✔️ |

