Android 跳转到第三方地图App实现方案,目标地点定位、地点附近关键字搜索
方案
Android 跳转到第三方地图App实现方案
Android 跳转到高德地图、腾讯地图、百度地图。
跳转到第三方地图目标地点定位、目标地点附近关键字搜索
官方链接
高德地图:https://lbs.amap.com/api/amap-mobile/guide/android/route
腾讯地图:https://lbs.qq.com/uri_v1/guide-mobile-navAndRoute.html
百度地图:http://lbsyun.baidu.com/index.php?title=uri/api/ios&qq-pf-to=pcqq.c2c
代码
class NavigationUtils {
companion object {
val JUMP_GAO_DE = "JUMP_GAO_DE"
val JUMP_TEN_XUN = "JUMP_TEN_XUN"
val JUMP_BAI_DU = "JUMP_BAI_DU"
private val PACKAGE_GAO_DE = "com.autonavi.minimap"
private val PACKAGE_TEN_XUN = "com.tencent.map"
private val PACKAGE_BAI_DU = "com.baidu.BaiduMap"
private val TYPE_AROUND = false
@JvmStatic
fun jumpNavigation(context: Context, type: String, lat: String, lon: String, poiname: String) {
try {
val intent = Intent()
when (type) {
JUMP_GAO_DE -> {
if (isInstall(PACKAGE_GAO_DE)) {
if (TYPE_AROUND) {
val keyWords = "美食"
intent.data =
Uri.parse("androidamap://arroundpoi?sourceApplication=my&keywords=$keyWords&lat=$lat&lon=$lon&dev=0");
} else {
intent.data =
Uri.parse("androidamap://viewMap?sourceApplication=my&poiname=$poiname&lat=$lat&lon=$lon&dev=0")
}
context.startActivity(intent)
} else {
goToMarket(context, PACKAGE_GAO_DE)
}
}
JUMP_TEN_XUN -> {
if (isInstall(PACKAGE_TEN_XUN)) {
if (TYPE_AROUND) {
val keyWords = "篮球场"
intent.data =
Uri.parse("qqmap://map/nearby?coord:$lat,$lon;placeName=$keyWords&radius=5000&referer=myapp")
} else {
intent.data =
Uri.parse("qqmap://map/marker?marker=coord:$lat,$lon;title:$poiname;addr: &referer=myapp")
}
context.startActivity(intent)
} else {
goToMarket(context, PACKAGE_TEN_XUN)
}
}
JUMP_BAI_DU -> {
if (isInstall(PACKAGE_BAI_DU)) {
if (TYPE_AROUND) {
val keyWords = "公园"
intent.data = Uri.parse("baidumap://map/place/nearby?query=$keyWords¢er=$lat,$lon&radius=1000")
} else {
intent.data =
Uri.parse("baidumap://map/marker?location=$lat,$lon&title=$poiname&content=&traffic=on")
}
context.startActivity(intent)
} else {
goToMarket(context, PACKAGE_BAI_DU)
}
}
}
} catch (e: Exception) {
TLog.e("openNavigation: ", e.toString());
ToastUtils.showShort("请检查是否开启定位权限");
}
}
private fun isInstall(packageName: String): Boolean {
return File("/data/data/$packageName").exists()
|| File("storage/emulated/0/Android/data/$packageName").exists()
}
private fun goToMarket(context: Context, packageName: String) {
try {
val uri: Uri = Uri.parse("market://details?id=$packageName")
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
context.startActivity(goToMarket)
} catch (e: ActivityNotFoundException) {
}
}
}
}
写在最后
此文章为个人开发时记录,有时时间有限,无法深入研究,若看到此文章后有其他见解或解决方式,欢迎留言交流👇👇👇
———————————————— 版权声明:转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_44158429/article/details/125780430
|