react-native mapbox is not showing user location and annotation

心已入冬 提交于 2020-06-29 20:41:14

问题


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>
  );
}

}


回答1:


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);
    });
}


来源:https://stackoverflow.com/questions/50195118/react-native-mapbox-is-not-showing-user-location-and-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!