react-native映射框未显示用户位置和注释 [英] react-native mapbox is not showing user location and annotation
问题描述
我目前正在使用 mapbox
https://github.com/mapbox/react-native-mapbox-gl 如果我给了它 lon
和 lat
它确实在我的 emulator
上显示了一个位置,但是问题是 annotation
和 show user location
完全没有显示.>
有人知道我可能会缺少什么吗?我已经重新构建了几次应用程序,并检查了调试,但没有错误
这是我的简单代码
导出默认类App扩展了组件{数据= [{ ID: '' }];使成为() {返回 (<视图样式={styles.container}>< Mapbox.MapViewshowUserLocation = {true}styleURL = {Mapbox.StyleURL.Street}zoomLevel = {16}centerCoordinate = {[-123.1118716,49.2847564]}style = {styles.container}></Mapbox.MapView>< Mapbox.PointAnnotationid ='1'title ='nooooooooooooooooooooooo'坐标={[-123.1118716, 49.2847560]}></Mapbox.PointAnnotation></View>);}}
遇到相同的问题,在Android> = 23上,您必须先请求权限
import'react-native'的{PermissionsAndroid};...componentDidMount(){{PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,权限Android.PERMISSIONS.ACCESS_COARSE_LOCATION],{标题:授予位置许可",消息:应用需要位置权限才能找到您的位置."}).then(granted => {console.log(已授予);解决();}).catch(err => {console.warn(err);拒绝(错误);});}
I am currently learning react-native with maps using mapbox
https://github.com/mapbox/react-native-mapbox-gl I followed everything that the map shows, if I give it a lon
and lat
it does show a location on my emulator
but the problem is the annotation
and show user location
doesn't show at all.
Does anyone have any idea what I might be missing? I have been rebuilding the app a few times and checked debugging that there is no errors though
here is my simple code
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>
);
}
}
Ran into the same issue, on Android >=23 you have to ask for permissions first
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);
});
}
这篇关于react-native映射框未显示用户位置和注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!