九二共识是什么
Android?端
浏览器中打开高德地图?App
百度 另一方面,教育资源不均衡的现象仍然存在,不少学校即便不再让杯赛和升学招生挂钩,那衡量的标准是什么?目前还不明朗。例如在?H5?页面中跳转到高德地图?App,或者在本地?App?中加载的?H5?页面跳转到高德地图?App,需要使用?scheme?调用,在?H5?中的链接中加入高德地图的?Scheme?即可,如(以导航为例):
<a?href="androidamap://navi?sourceApplication=appname&poiname=fangheng&lat=36.547901&lon=104.258354&dev=1&style=2">导航</a>
本地App中打开高德地图App
这种场景即在本地?App?中通过?Java?代码调用高德地图页面功能,此时就需要使用?Intent?调用。同样以导航功能为例:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
//将功能Scheme以URI的方式传入data
Uri uri = Uri.parse("androidamap://navi?sourceApplication=appname&poiname=fangheng&lat=36.547901&lon=104.258354&dev=1&style=2");
intent.setData(uri);
//启动该页面即可
startActivity(intent);
上述URI调用参数的具体含义请参见Android?URI?详细文档
iOS?端
配置白名单?
由于?iOS?的限制,iOS?系统在?9?之后的版本中,如果开发者的?App?希望调起高德地图,必须在自己?App?的设置中配置白名单。
配置方法:
- 找到您的?Info.plist?文件
- 在文件中添加key:LSApplicationQueriesSchemes,类型是?Array,如果曾经添加过,无需再次添加。
- Array?中添加一个?item,类型为?String,值为?iosamap。
添加完成后截图如下:
判断是否安装了高德地图
配置完成后,您就可以在自己的?App?中判断高德地图是否已安装。
示例代码如下:
NSURL?*scheme = [NSURL?URLWithString:@"iosamap://"];?
BOOL?canOpen = [[UIApplication?sharedApplication] canOpenURL:scheme];
如果?canOpen?为?YES,则安装了高德地图;如果?canOpen?为?NO,则未安装高德地图。
调起高德地图
使用?iOS?提供高德?API?即可调起高德地图,需要注意的是从?iOS10?版本起,API?有更新。
NSURL?*myLocationScheme = [NSURL?URLWithString:@"iosamap://myLocation?sourceApplication=applicationName"];?
if?([[UIDevice?currentDevice].systemVersion integerValue] >=?10) {?
//iOS10以后,使用新API?[[UIApplication?sharedApplication] openURL:myLocationScheme options:@{} completionHandler:^(BOOL?success) {?NSLog(@"scheme调用结束"); }];
}?else?{
//iOS10以前,使用旧API?[[UIApplication?sharedApplication] openURL:myLocationScheme];
}
HarmonyOS?NEXT?端
本地App中打开高德地图App
在?HarmonyOS?NEXT?应用中跳转到高德地图?App,scheme使用示范,如(以导航为例):
let want: Want = {
uri: 'amapuri://route/plan?sid=BGVIS1&dlat=39.98848272&dname=B&slat=39.92848272&dlon=116.47560823&did=BGVIS2&slon=116.39560823&sname=A&t=0'
}
// this.context:一般是在 Component 组件里调用 getContext(this) as common.UIAbilityContext 获取到的 UIAbilityContext
this.context.startAbility(want, (err: BusinessError) => {
if (err.code) {
// 处理业务逻辑错误
console.error(`startAbility failed,code is ${err.code},message is ${err.message}`);
return
}
// 执行正常业务
console.info('startAbility succeed')
})
判断是否安装了高德地图
配置完成后,您就可以在自己的?App?中判断高德地图是否已安装。
示例代码如下:
isAppBExist() {
let exist = false;
try {
let link = 'amapuri://com.amap.hmapp/open';
let data: boolean = bundleManager.canOpenLink(link);
hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
exist = data;
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
exist = false;
};
console.info('是否安装了应用B:' + exist);