我正在使用创建反应原生应用来运行此应用但尚未退出(我已备份以防万一)。我已经尝试弹出这个项目,但错误仍然存在。
我已在AndroidManifest.xml中添加了以下代码。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我不知道我项目中的AndroidManifest.xml是否正确,因为我在
中添加了这段代码\node_modules\react-native-maps\lib\android\src\main\AndroidManifest.xml
这是我的代码:
watchID = null
componentDidMount(){
navigator.geolocation.getCurrentPosition((position) => {
var lat = parseFloat(position.coords.latitude);
var long = parseFloat(position.coords.longitude);
var initialRegion = {
latitude: lat,
longitude: long,
latitudeDelta: latitude_Delta,
longitudeDelta: longitude_Delta,
}
this.setState({initialPosition: initialRegion});
this.setState({markerPosition: initialRegion});
},
(error) => {alert('Current Location: ERROR(' + error.code + '): ' + error.message)},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
)
this.watchID = navigator.geolocation.watchPosition((position) => {
var lat = parseFloat(position.coords.latitude);
var long = parseFloat(position.coords.longitude);
var lastRegion = {
latitude: lat,
longitude: long,
latitudeDelta: latitude_Delta,
longitudeDelta: longitude_Delta,
}
this.setState({initialPoisition: lastRegion});
this.setState({markerPosition: lastRegion});
},
(error) => {alert('Watch Position: ERROR(' + error.code + '): ' + error.message)},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000, distanceFilter: 10 })
}
componentWillUnmount(){
navigator.geolocation.clearWatch(this.watchID)
}
答案 0 :(得分:0)
它为我工作,
_this.watchID = navigator.geolocation.watchPosition((position) => {
console.log(TAG + "position : " + JSON.stringify(position));
var gps_location = position.coords.latitude + "," + position.coords.longitude;
console.log(TAG + "gps_location : " + JSON.stringify(gps_location));
}, error => {
console.log(TAG + " error in getting location " + error);
}, {
enableHighAccuracy: false, timeout: 20000, maximumAge: 1000
});