传单:如何在谷歌地图/Waze本地应用程序中打开一个地方并使用它进行导航



我正在使用Ionic React/React Native开发一个移动应用程序。我想使用Leaflet来显示静态地图和标记。如果用户单击标记,我希望在Google Map/Waze/任何本地地图应用程序中打开坐标,然后使用该本地应用程序将用户导航到标记中。

有没有办法将marked place打开到本地地图应用程序中?

谷歌地图提供了跨平台的深度链接通用URL。如果安装了本机谷歌地图应用程序。它将使用该应用程序打开,否则,使用安装在用户设备上的默认web浏览器。

您可以使用React Native Linking API动态链接到特定位置。

import { Linking, Alert } from "react-native";
async function openWithGoogleMap() {
/** Google Map API offers different URL to deep link to various locatioon and map ressources.
* Check their docs - https://developers.google.com/maps/documentation/urls/get-started
*/
const url =
"https://www.google.com/maps/search/?api=1&query=47.5951518%2C-122.3316393";
const supported = await Linking.canOpenURL(url);
if (supported) {
// Opening the link with some app, if the URL scheme is "http" the web link should be opened
// by some browser in the mobile
await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open this URL: ${url}`);
}
}

最新更新