[英]Ionic 3 - Open geolocation without navigation with Google Maps / Apple Maps app
In my Ionic 3 app for Android
and iOS
, I need to open a specific geolocation with Google Maps
(if installed) or Apple Maps
.在适用于Android
和iOS
Ionic 3应用程序中,我需要使用Google Maps
(如果已安装)或Apple Maps
打开特定的地理位置。 I discovered Launch Navigator which pretty much does the same.我发现Launch Navigator 的功能几乎相同。
marker
using Launch Navigator ?有没有办法让我选择不导航到指定位置而只使用Launch Navigator显示marker
?I had the same issue and this is what I came up with.我有同样的问题,这就是我想出的。 There are three important steps有三个重要步骤
import { Platform } from 'ionic-angular';
需要包括 Platform import { Platform } from 'ionic-angular';
import { LaunchNavigator, LaunchNavigatorOptions } from '@ionic-native/launch-navigator';
import { InAppBrowser } from '@ionic-native/in-app-browser';
then we have all we need to open Google Maps on iOS if it's available, with no navigation那么我们就拥有了在 iOS 上打开谷歌地图所需的一切(如果有的话),没有导航
if (this.platform.is('ios')) {
//try google maps first
this.launchNavigator.isAppAvailable(this.launchNavigator.APP.GOOGLE_MAPS).then(
response => {
if(response) {
window.open('comgooglemaps://?q=' + lat + ',' + lng + '(' + marker_name + ')', '_system');
}
else {
window.open('maps://?q=' + lat + ',' + lng, '_system');
}
},
failure => {
//check failed;
}
);
}
else if (this.platform.is('android')) {
window.open('geo://' + lat + ',' + lng + '?q=' + lat + ',' + lng + '(' + marker_name + ')', '_system');
}
Try this, it let the user to choose the app navigation ( waze or map or...) to open, and add a marker on latitude and longitude given:试试这个,它让用户选择要打开的应用程序导航(位智或地图或...),并在给定的纬度和经度上添加标记:
import { Platform } from '@ionic/angular';
...
constructor(
public platform: Platform
) {
}
public openMapsApp(lat: number, lng: number) {
const geocoords = lat + ',' + lng;
if (
this.platform.is('ios')
&& this.platform.is('iphone')
&& this.platform.is('ipad')
) {
window.open('maps://?q=' + geocoords, '_system');
return;
}
if (this.platform.is('desktop')) {
window.open('https://www.google.com/maps?q=' + geocoords);
return;
}
const label = encodeURI('7 East Street'); // encode the label!
window.open('geo:' + geocoords + '?q=' + geocoords + '(' + label + ')', '_system');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.