map_launcher 2.1.1
map_launcher: ^2.1.1 copied to clipboard

Map Launcher is a flutter plugin to find available maps installed on a device and launch them with a marker or show directions.

Map Launcher #

pub package likes popularity pub points GitHub stars GitHub forks

Map Launcher is a flutter plugin to find available maps installed on a device and launch them with a marker or show directions.

MarkerNavigation
MarkerNavigation

Currently supported maps:
Google Maps
Apple Maps (iOS only)
Google Maps GO (Android only)
Baidu Maps
Amap (Gaode Maps)
Waze
Yandex Maps
Yandex Navigator
Citymapper
Maps.me
OsmAnd
OsmAnd+ (Android only)
2GIS
Tencent (QQ Maps)
HERE WeGo

Breaking Change in v1.1.3 #

Because of the changes in Android 11 you may need to adjust your gradle version if it's failing to build. You can find solution here

Migrating to v1 #

Breaking change: map_launcher does not depend on flutter_svg anymore which means you will have to add flutter_svg in your project if you want to use images.

This should allow you to use any version of flutter_svg and it also fixes bunch of issues related to that like #45, #40, etc

The icon property from AvailableMap now returns String instead of ImageProvider so to get it working all you have to do is to go from

Image(
  image: map.icon,
)

to

import 'package:flutter_svg/flutter_svg.dart';

SvgPicture.asset(
  map.icon,
)

Get started #

Add dependency #

dependencies:
  map_launcher: ^2.1.1
  flutter_svg: # only if you want to use icons as they are svgs

For iOS add url schemes in Info.plist file #

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
    <string>baidumap</string>
    <string>iosamap</string>
    <string>waze</string>
    <string>yandexmaps</string>
    <string>yandexnavi</string>
    <string>citymapper</string>
    <string>mapswithme</string>
    <string>osmandmaps</string>
    <string>dgis</string>
    <string>qqmap</string>
    <string>here-location</string>
</array>

Usage #

Get list of installed maps and launch first #

import 'package:map_launcher/map_launcher.dart';

final availableMaps = await MapLauncher.installedMaps;
print(availableMaps); // [AvailableMap { mapName: Google Maps, mapType: google }, ...]

await availableMaps.first.showMarker(
  coords: Coords(37.759392, -122.5107336),
  title: "Ocean Beach",
);

Check if map is installed and launch it #

import 'package:map_launcher/map_launcher.dart';

if (await MapLauncher.isMapAvailable(MapType.google)) {
  await MapLauncher.showMarker(
    mapType: MapType.google,
    coords: coords,
    title: title,
    description: description,
  );
}

API #

Show Marker #

optiontyperequireddefault
mapTypeMapTypeyes-
coordsCoords(lat, long)yes-
titleStringno''
descriptionStringno''
zoomIntno16
extraParamsMap<String, String>no{}
Maps
mapTypecoordstitledescriptionzoomextraParams
.googleiOS only
see Known Issues section below
.apple
.googleGo
.amapAndroid only
.baidu
.waze
.yandexMaps
.yandexNavi
.citymapper
does not support marker
shows directions instead
.mapswithme
.osmandiOS only
.osmandplusiOS only
.doubleGis
android does not support marker
shows directions instead
.tencent
.here

Show Directions #

optiontyperequireddefault
mapTypeMapTypeyes-
destinationCoords(lat, long)yes-
destinationTitleStringno'Destination'
originCoords(lat, long)noCurrent Location
originTitleStringno'Origin'
directionsModeDirectionsModeno.driving
waypointsList<Coords(lat, long)>nonull
extraParamsMap<String, String>no{}
Maps
mapTypedestinationdestinationTitleoriginoriginTitledirectionsModewaypointsextraParams
.google✓ (up to 8 on iOS and unlimited? on android)
.apple
.googleGo
.amap
.baidu
.wazealways uses current location
.yandexMaps
.yandexNavi
.citymapper
.mapswithmeonly shows marker
.osmandiOS onlyalways uses current location
.osmandplusiOS onlyalways uses current location
.doubleGis
.tencent
.here

Extra Params #

It's possible to pass some map specific query params like api keys etc using extraParams option

Here are known params for some maps:

mapTypeextraParams
.tencent{ 'referer': '' }
.yandexNavi{ 'client': '', 'signature': '' }

Example #

Using with bottom sheet #

import 'package:flutter/material.dart';
import 'package:map_launcher/map_launcher.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() => runApp(MapLauncherDemo());

class MapLauncherDemo extends StatelessWidget {
  openMapsSheet(context) async {
    try {
      final coords = Coords(37.759392, -122.5107336);
      final title = "Ocean Beach";
      final availableMaps = await MapLauncher.installedMaps;

      showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return SafeArea(
            child: SingleChildScrollView(
              child: Container(
                child: Wrap(
                  children: <Widget>[
                    for (var map in availableMaps)
                      ListTile(
                        onTap: () => map.showMarker(
                          coords: coords,
                          title: title,
                        ),
                        title: Text(map.mapName),
                        leading: SvgPicture.asset(
                          map.icon,
                          height: 30.0,
                          width: 30.0,
                        ),
                      ),
                  ],
                ),
              ),
            ),
          );
        },
      );
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Map Launcher Demo'),
        ),
        body: Center(child: Builder(
          builder: (context) {
            return MaterialButton(
              onPressed: () => openMapsSheet(context),
              child: Text('Show Maps'),
            );
          },
        )),
      ),
    );
  }
}

Known issues #

  • Google Maps for Android have a bug that setting label for a marker doesn't work. See more on Google Issue Tracker

  • On iOS it's possible to "delete" Apple Maps which actually just removes it from homescreen and does not actually delete it. Because of that Apple Maps will always show up as available on iOS. You can read more about it here

Contributing #

Pull requests are welcome.

270
likes
110
pub points
97%
popularity

Publisher

fluttered.dev

Map Launcher is a flutter plugin to find available maps installed on a device and launch them with a marker or show directions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on map_launcher