Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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');
};
});
});
};
}
@Bloggerschmidt

This comment has been minimized.

Copy link
Owner Author

commented Sep 20, 2016

cordova plugin add cordova-plugin-geolocation
@rafaelbatistamarcilio

This comment has been minimized.

Copy link

commented Oct 29, 2017

Hello Friend,

Do you know how to open the map with the route from the position of the device to the reported coordinates?

map

Thanks for the previous post, it helped a lot !!

@yuan8

This comment has been minimized.

Copy link

commented Nov 11, 2017

so its solved?

@ShafiqShams

This comment has been minimized.

Copy link

commented Nov 22, 2017

Thank you so very much <3

@skydevelopers

This comment has been minimized.

Copy link

commented Apr 8, 2018

I am a beginner in Ionic from skd please tell me what are the variables here in the above code

@fagianijunior

This comment has been minimized.

Copy link

commented Apr 9, 2018

HI, thank you for the code.
This open the maps, but when I press back button on android it go back to my app and relaunch the map again.
If I change to my app it relaunch the map again. Like a redirect page when you press back in navigator.

@alfonso100

This comment has been minimized.

Copy link

commented May 23, 2018

I had an issue with opening links to google maps app, from my Ionic app. The user location was not available so the user wasn't able to navigate.
This plugin solved the issue!

@melovinpogi

This comment has been minimized.

Copy link

commented Sep 14, 2018

updated syntax for ios 11+ ionic 3

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.