我想让我的按钮onPress功能来调用一个函数,将打开苹果地图或谷歌地图取决于设备。出于某种原因,当我按下按钮时没有任何事情发生。反应本机开放本地地图
这里是我的功能:
openMap=() => {
console.log('open directions')
Platform.select({
ios:() => {
Linking.openURL('http://maps.apple.com/maps?daddr=');
},
android:() => {
Linking.openURL('http://maps.google.com/maps?daddr=');
}
});
}
下面是按钮:
<TouchableOpacity
onPress={this.openMap}
style={styles.navigateBtn}>
<Icon name="md-navigate" style={{ fontSize: 24 }} />
<Text
style={{ fontSize: 13, fontWeight: "700", lineHeight: 14 }}
>
NAVIGATE
</Text>
</TouchableOpacity>
最后,我想通过经度和纬度进入openMap函数来获取行车路线,但首先我需要获得地图打开。
这是我进口
import { View, TouchableOpacity, Modal, Platform, Alert, StyleSheet, Linking } from "react-native";
import {Header, Content, Text, Button, Icon, Card,CardItem, Title, Left, Right, Body, Container
} from "native-base";
import { Constants } from 'expo
@查尔斯 - 奥利弗·德默斯那是一个错字opps!接得好。在我的代码中,“onPress = {this.openMap}”仍然不工作:( –
你的openMap被调用了吗?你看到你的console.log吗? –
试试看我的新答案 –