Bob.Tern
Posts: 15
Joined: Wed Nov 15, 2023 7:02 am

Open Google Maps app (rather than Google Maps webpage) directly

I want my app to have a link which can open Google Maps app (rather than Google Maps webpage) directly. How can I do it?
aantsypau
Posts: 29
Joined: Wed May 24, 2023 7:57 am

Re: Open Google Maps app (rather than Google Maps webpage) directly

You can use the following approach which open external application which is registered as default map app

const query = "53.723337, -69.995790";
if (this.$a.isIOS()) {
window.location.href = encodeURI(`maps://?q=${query}`);
} else if (this.$a.isAndroid()) {
window.open(encodeURI(`geo:0,0?q=${query}`), "_system");
}

Alternatively you can open particular application and pass parameters using Launch Navigator plugin

image.png

The following code check if Google Map app is installed and if yes then open it for particular address or coordinates

window.launchnavigator?.isAppAvailable(window.launchnavigator.APP.GOOGLE_MAPS, (isAvailable) => {
var app;
if (isAvailable) {
app = window.launchnavigator.APP.GOOGLE_MAPS;
} else {
console.warn("Google Maps not available - falling back to user selection");
app = window.launchnavigator.APP.USER_SELECT;
}
window.launchnavigator.navigate("London, UK", {
app: app
});
});

More information about this plugin you can read here https://github.com/dpa99c/phonegap-launch-navigator

Please pay attention that for building android app it is needed to pass plugin parameter GOOGLE_API_KEY_FOR_ANDROID
Attachments
image (1).png
image (1).png (128.64 KiB) Viewed 22428 times

Return to “Issues”