getLatestLocation() 返回 null 并且 subscribeToLocationUpdates 永远不会触发:
import RNLocation from 'react-native-location';
RNLocation.requestPermission({
ios: 'whenInUse',
android: {detail: 'coarse'},
}).then((granted) => {
if (granted) {
RNLocation.getLatestLocation().then((loc) => {
Alert.alert(JSON.stringify(loc)); // <--- this returns null
});
RNLocation.subscribeToLocationUpdates((locations) => { // <-- this never fires
const {latitude, longitude} = locations[0];
Alert.alert(`${JSON.stringify({latitude, longitude})}`);
});
}
});`