繁体   English   中英

Ionic 3 - 使用 Google Maps / Apple Maps 应用程序无需导航即可打开地理定位

[英]Ionic 3 - Open geolocation without navigation with Google Maps / Apple Maps app

在适用于AndroidiOS Ionic 3应用程序中,我需要使用Google Maps (如果已安装)Apple Maps打开特定的地理位置。 我发现Launch Navigator 的功能几乎相同。

  1. 有没有办法让我选择不导航到指定位置而只使用Launch Navigator显示marker
  2. 如果没有,是否还有其他选择可以使这成为可能?

我有同样的问题,这就是我想出的。 有三个重要步骤

  1. 检查用户是在 iOS 还是 Android 上
    • 需要包括 Platform import { Platform } from 'ionic-angular';
  2. 如果他们在 iOS 上检查谷歌地图
    • 我正在使用 LaunchNavigator 检查应用程序
      import { LaunchNavigator, LaunchNavigatorOptions } from '@ionic-native/launch-navigator';
  3. 使用我们的 GPS 参数打开相应的应用程序
    • 要打开外部应用程序,我们需要应用程序内浏览器
      import { InAppBrowser } from '@ionic-native/in-app-browser';

那么我们就拥有了在 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');
}

试试这个,它让用户选择要打开的应用程序导航(位智或地图或...),并在给定的纬度经度上添加标记:

  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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM