我目前正在使用mapbox
学习react-native和 map https://github.com/mapbox/react-native-mapbox-gl我遵循了 map 显示的所有内容,如果我给它一个lon
和lat
,它确实会在我的模拟器
上显示一个位置,但问题是注释
和显示用户位置
根本不显示。
有人知道我可能会错过什么吗? 我已经重建了应用程序几次并检查了调试是否没有错误
这是我的简单代码
export default class App extends Component {
data = [
{ id: '' }
];
render() {
return (
<View style={styles.container}>
<Mapbox.MapView
showUserLocation={true}
styleURL={Mapbox.StyleURL.Street}
zoomLevel={16}
centerCoordinate={[-123.1118716, 49.2847564]}
style={styles.container}>
</Mapbox.MapView>
<Mapbox.PointAnnotation
id='1'
title='nooooooooooooooooooooo'
coordinate={[-123.1118716, 49.2847560]}
>
</Mapbox.PointAnnotation>
</View>
);
}
}
最佳答案
遇到同样的问题,在 Android >=23 上,您必须先请求权限
import { PermissionsAndroid } from 'react-native';
...
componentDidMount() {
{
PermissionsAndroid.requestMultiple(
[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION],
{
title: 'Give Location Permission',
message: 'App needs location permission to find your position.'
}
).then(granted => {
console.log(granted);
resolve();
}).catch(err => {
console.warn(err);
reject(err);
});
}
关于javascript - React-Native Mapbox 不显示用户位置和注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50195118/