【发布时间】:2021-10-29 23:07:18
【问题描述】:
我正在开发一个使用 Google Map 的 react native expo 应用程序。模拟器上一切正常,地图工作并显示标记。但在真机上不显示,没有黑屏或异常!
我知道调试和发布 API 密钥,我确信这部分没有任何问题。该应用的调试版和发布版都在真机上进行了测试,但结果相同。
app.json
"android": {
"package": "com.example.packegename",
"config": {
"googleMaps": {
"apiKey": "API_KEY"
}
},
"googleServicesFile": "./google-services.json"
}
mapView.js
const { status } = await Location.requestForegroundPermissionsAsync();
Location.installWebGeolocationPolyfill()
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
userLat: position.coords.latitude,
userLong: position.coords.longitude,
userLatLoaded:true,
mapRegion: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0.1,
longitudeDelta: 0.1,
},
});
this.fetchData();
},
(error) => console.log('user location getting error - '+ error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
);
return Location.getCurrentPositionAsync({enableHighAccuracy: true});
} else {
throw new Error('Location permission not granted');
}
【问题讨论】:
标签: android react-native google-maps expo