Skip to content

Commit

Permalink
Support arbitrary platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
pikaju committed Jan 17, 2020
1 parent 2797d84 commit 2daaac9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.0

* Add support support for arbitrary platforms (Google Maps)

## 1.1.0

* Add Flutter Web support (Google Maps)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Maps launcher for Flutter

A simple package that uses [url_launcher](https://pub.dev/packages/url_launcher) to
launch the maps app with the proper scheme on iOS, Android and the web.
launch the maps app with the proper scheme on all platforms.

On iOS, map links [as specified by Apple](https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html) are launched.
On Android, the geo intent is used as documented [here](https://developer.android.com/guide/components/intents-common.html#Maps).
For web, the plugin will simply launch [Google Maps](https://developers.google.com/maps/documentation/urls/guide).
For web and other platforms, the plugin will simply launch [Google Maps](https://developers.google.com/maps/documentation/urls/guide).

## Usage

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.0"
version: "1.2.0"
matcher:
dependency: transitive
description:
Expand Down
44 changes: 21 additions & 23 deletions lib/maps_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,38 @@ class MapsLauncher {
/// to open a maps application showing the result of a search query.
/// Returns `null` if the platform is not supported.
static String createQueryUrl(String query) {
if (kIsWeb) {
return Uri.encodeFull(
'https://www.google.com/maps/search/?api=1&query=$query');
if (!kIsWeb) {
if (Platform.isAndroid) {
return Uri.encodeFull('geo:0,0?q=$query');
} else if (Platform.isIOS) {
return Uri.encodeFull('https://maps.apple.com/?q=$query');
}
}
if (Platform.isAndroid) {
return Uri.encodeFull('geo:0,0?q=$query');
} else if (Platform.isIOS) {
return Uri.encodeFull('https://maps.apple.com/?q=$query');
}
return null;
return Uri.encodeFull(
'https://www.google.com/maps/search/?api=1&query=$query');
}

/// Returns a URL that can be launched on the current platform
/// to open a maps application showing coordinates ([latitude] and [longitude]).
/// Returns `null` if the platform is not supported.
static String createCoordinatesUrl(double latitude, double longitude,
[String label]) {
if (kIsWeb) {
return Uri.encodeFull(
'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude');
}
if (Platform.isAndroid) {
return Uri.encodeFull(
'geo:0,0?q=$latitude,$longitude' + (label == null ? '' : '($label)'),
);
} else if (Platform.isIOS) {
if (label != null)
if (!kIsWeb) {
if (Platform.isAndroid) {
return Uri.encodeFull(
'https://maps.apple.com/?q=$label&ll=$latitude,$longitude',
'geo:0,0?q=$latitude,$longitude' + (label == null ? '' : '($label)'),
);
else
return 'https://maps.apple.com/?sll=$latitude,$longitude';
} else if (Platform.isIOS) {
if (label != null)
return Uri.encodeFull(
'https://maps.apple.com/?q=$label&ll=$latitude,$longitude',
);
else
return 'https://maps.apple.com/?sll=$latitude,$longitude';
}
}
return null;
return Uri.encodeFull(
'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude');
}

/// Launches the maps application for this platform.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: maps_launcher
description: Simple Flutter package to open the maps application on iOS and Android.
version: 1.1.0
version: 1.2.0
homepage: https://github.com/Pikaju/FlutterMapsLauncher

environment:
Expand Down

0 comments on commit 2daaac9

Please sign in to comment.