CLLocationErrorEvent: error property
The error property is the location error.
Value
A CLLocationError: a DOMException or an NSError. name is the error's category.
- Read-only. Assigning to it throws
TypeError. - Without authorization,
nameis'NotAllowedError'. - When the location can't be determined for now,
nameis'LocationUnknownError', and the system keeps trying. - The system's error code and domain: an
NSErrorhas its owncodeanddomain; aDOMExceptionhas them oncause. - When the event is created with
newwithout it, it isnull.
Examples
js
const manager = new CLLocationManager();
manager.addEventListener('locationerror', (e) => {
if (e.error.name === 'NotAllowedError') {
manager.stopUpdatingLocation();
console.log('没有权限,停止定位');
}
});
manager.startUpdatingLocation();Effect: without location permission, stops updating and prints 没有权限,停止定位. Not verified in the simulator.
Corresponding iOS API
The error parameter of locationManager:didFailWithError:.