我目前正在开发一个使用手机地理定位服务的项目。
目前我遇到了一个问题,它显示我的地理定位未被授权。
我已经在互联网上搜索过,有几个人也遇到了同样的问题,但我并没有解决它。
componentDidMount() {
const { coordinate } = this.state;
this.requestCameraPermission();
this.watchID = navigator.geolocation.watchPosition(
position => {
const { routeCoordinates, distanceTravelled } = this.state;
const { latitude, longitude } = position.coords;
const newCoordinate = {
latitude,
longitude
};
console.log({ newCoordinate });
coordinate.timing(newCoordinate).start();
this.setState({
latitude,
longitude,
routeCoordinates: routeCoordinates.concat([newCoordinate]),
distanceTravelled:
distanceTravelled + this.calcDistance(newCoordinate),
prevLatLng: newCoordinate
});
},
error => console.log(error),
{
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 1000,
distanceFilter: 10
}
);
}
我当前的位置应该出现在屏幕上,但是却显示在地图默认位置:旧金山。当使用函数navigator.geolocation.watchPosition时,会出现以下错误:
"code": "E_LOCATION_UNAUTHORIZED", "message": "Not authorized to use location services", "watchId": 1,
我的手机是三星S9,并且定位服务已启用...所以我对目前遇到的问题非常好奇。