react-native - 如何在反应原生地图链接中添加参数或变量
问题描述
export default function ViewData({ route, navigation }) {
const { email, id, rideID, Source, Dest } = route.params;
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Details Screen</Text>
<Text>otherParam: {JSON.stringify(email)}</Text>
<Text>otherParam: {JSON.stringify(id)}</Text>
<Text>otherParam: {JSON.stringify(rideID)}</Text>
<TouchableOpacity
onPress={() => Linking.openURL("google.navigation:q=" + { Source })}
>
<Text>CLick here to navigate to customer</Text>
</TouchableOpacity>
<Text>{Source}</Text>
</View>
);
}
我是 React Native 编码的新手,无法弄清楚我的变量是否存在,只是没有传递给链接。
来源= 39.0437567 -77.4874416
如果我粘贴纬度并登录谷歌地图,它会将我带到那里。
谢谢
解决方案
我使用这个功能,它对我有用
第一的import {Platform, Linking} from 'react-native';
此功能在 android 中打开谷歌地图,在ios 中打开苹果地图
const openMapApp = (latitude, longitude) => {
if (Platform.OS === 'android') {
Linking.openURL(`google.navigation:q=${latitude},${longitude}`);
}else{
Linking.openURL(`http://maps.apple.com/?daddr=${latitude},${longitude}`)
}
};
此功能在 android 和 ios 中打开谷歌地图
const openGoogleMapApp = (latitude, longitude) => {
if (Platform.OS === 'android') {
Linking.openURL(`google.navigation:q=${latitude},${longitude}`);
}else{
Linking.openURL(`https://www.google.com/maps/?daddr=${latitude},${longitude}`);
}
};
推荐阅读
- .net-core - Powershell,独立 OK,但脚本输出只是换行符
- visual-studio-code - VSCode:如何配置我的项目以自动激活 Python 扩展?
- powerbi - 将平均线添加到堆积柱形图
- html - Universo HTML 主题 CSS 自定义
- reactjs - Updating a state array
- sdk - JS 组件安装失败:在 DevEco studio 中安装 JS sdk 时
- python - 如何在指定项目之后的列表/字符串/范围中查找特定项目?
- python - 不和谐机器人。通过从数据库中提取数据并将其嵌入来做出反应
- android - 在mac上运行集成测试时如何授予android权限?
- pip - 退出我的代理服务器时 pip 失去连接