Skip to content

Instantly share code, notes, and snippets.

@schmidt1024
Last active October 5, 2021 17:23
Show Gist options
  • Save schmidt1024/aec7ed3dae3262d975d6d53009ef6aa8 to your computer and use it in GitHub Desktop.
Save schmidt1024/aec7ed3dae3262d975d6d53009ef6aa8 to your computer and use it in GitHub Desktop.
start external map navigation from ionic 2 app for ios and android; needs cordova-plugin-geolocation
startExternalMap() {
if (this.location.latitude) {
this.platform.ready().then(() => {
Geolocation.getCurrentPosition().then((position) => {
// ios
if (this.platform.is('ios')) {
window.open('maps://?q=' + this.location.name + '&saddr=' + position.coords.latitude + ',' + position.coords.longitude + '&daddr=' + this.location.latitude + ',' + this.location.longitude, '_system');
};
// android
if (this.platform.is('android')) {
window.open('geo://' + position.coords.latitude + ',' + position.coords.longitude + '?q=' + this.location.latitude + ',' + this.location.longitude + '(' + this.location.name + ')', '_system');
};
});
});
};
}
@melovinpogi
Copy link

updated syntax for ios 11+ ionic 3

window.open('maps://?q=' + address, '_system');

@maurosou
Copy link

import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';

constructor(public iab:InAppBrowser)

OpenMap(address) {
this.iab.create("https://maps.google.com/maps?q=" + address, "_blank");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment