import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AppAvailability } from '@ionic-native/app-availability';
import { Platform } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { WebIntent } from '@ionic-native/web-intent';
import * as $ from 'jquery';
import { Geolocation } from '@ionic-native/geolocation';
//地址
import { Diagnostic } from '@ionic-native/diagnostic';
//打开设置
import { OpenNativeSettings } from '@ionic-native/open-native-settings';
// enum Directions {
// Up,
// Down,
// Left,
// }
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public gaodisplay = false;
public baidisplay = false;
public schemeIntentgao;
public schemeIntentbai;
public urlgao;
public urlbaidu;
public lat=39.916485;
public lon=116.403119;
constructor(private appAvailability: AppAvailability,
public navCtrl: NavController,
private iab: InAppBrowser,
private platform: Platform,
private webIntent: WebIntent,
private geolocation: Geolocation,
private diagnostic: Diagnostic,
private openNativeSettings: OpenNativeSettings
) {
if (this.platform.is('ios')) {
this.schemeIntentgao = "iosamap://"
this.schemeIntentbai = "baidumap://";
} else if (this.platform.is('android')) {
this.schemeIntentgao = 'com.autonavi.minimap';
this.schemeIntentbai = "com.baidu.BaiduMap";
}
var number=0;
var interval = setInterval(() => {
if(number>1){
clearInterval(interval);
}
appAvailability.check(this.schemeIntentbai)
.then(
(yes: boolean) => document.getElementById('gao').style.display='block',
(no: boolean) => document.getElementById('gao').style.display='none'
);
appAvailability.check(this.schemeIntentgao).then(value=>{
this.gaodisplay=false
document.getElementById('baidu').style.display='block'
//打开app
},Error=>{
document.getElementById('baidu').style.display='none'
});
number++;
}, 100);
}
ionViewWillEnter() {
$(".background_div,.allTKOk").hide();
$(".background_div,.allTKOk_a").click(function(){
$(".background_div,.allTKOk").hide();
});
$("#open").click(function(){
$(".background_div,.allTKOk").show();
});
}
gao() {
if (this.platform.is('ios')) {
var sApp = (window as any).startApp.set("iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=39.92848272&slon=116.39560823&sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0");
sApp.start(function () {
alert("OK");
}, function (error) {
alert(error);
});
} else if (this.platform.is('android')) {
var sApp = (window as any).startApp.set({ //跳转对应APP
"action": "ACTION_VIEW",
"category": "CATEGORY_DEFAULT",
"type": "text/css",
"package": this.schemeIntentgao,
"uri":'amapuri://route/plan/?sid=BGVIS1&sname=我的位置&did=BGVIS2&dlat='+this.lat+'&dlon='+this.lon+'&dname=B&dev=0&t=0',
//我是选择路径规划然后导航的,当然你也可以直接用导航路径或者其他路径
"flags": ["FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_CLEAR_TASK"],
"intentstart": "startActivity",
}, { /* extras */
"EXTRA_STREAM": "extraValue1",
"extraKey2": "extraValue2"
});
sApp.start(function () { //跳转成功
alert("OK");
}, function (error) { //失败
alert(error);
});
}
}
baidu() {
if (this.platform.is('ios')) {
var sApp = (window as any).startApp.set('baidumap://map/navi?location='+this.lat+','+this.lon+'&type=BLK&src=ios.baidu.openAPIdemo');
sApp.start(function () {
alert("OK");
}, function (error) {
alert(error);
});
} else if (this.platform.is('android')) {
var sApp = (window as any).startApp.set({ //跳转对应APP
"action": "ACTION_VIEW",
"category": "CATEGORY_DEFAULT",
"type": "text/css",
"package": this.schemeIntentbai,
//我是选择路径规划然后导航的,当然你也可以直接用导航路径或者其他路径\
"uri":'baidumap://map/direction?destination=name:天安门|latlng:'+this.lat+','+this.lon+'&mode=driving&src=andr.baidu.openAPIdemo',
"flags": ["FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_CLEAR_TASK"],
"intentstart": "startActivity",
}, { /* extras */
"EXTRA_STREAM": "extraValue1",
"extraKey2": "extraValue2"
});
sApp.start(function () { //跳转成功
alert("OK");
}, function (error) { //失败
alert(error);
});
}
}
}
参考:https://blog.csdn.net/padding_scater/article/details/78997220