Send location uncertainty within a geo uri (#1309)

* Add uncertainty

* Add UTs

* Delete verticalAccuracy
This commit is contained in:
Alfonso Grillo
2023-07-12 11:02:05 +02:00
committed by GitHub
parent c573892954
commit adb253ff66
6 changed files with 57 additions and 11 deletions
@@ -57,6 +57,9 @@ struct MapLibreMapView: UIViewRepresentable {
@Binding var mapCenterCoordinate: CLLocationCoordinate2D?
@Binding var isLocationAuthorized: Bool?
// The radius of uncertainty for the location, measured in meters.
@Binding var geolocationUncertainty: CLLocationAccuracy?
/// Called when the user pan on the map
var userDidPan: (() -> Void)?
@@ -155,6 +158,7 @@ extension MapLibreMapView {
}
previousUserLocation = userLocation
updateGeolocationUncertainty(location: userLocation)
}
func mapView(_ mapView: MGLMapView, didChangeLocationManagerAuthorization manager: MGLLocationManager) {
@@ -176,13 +180,7 @@ extension MapLibreMapView {
mapLibreView.mapCenterCoordinate = mapView.centerCoordinate
}
}
// MARK: Callout
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
false
}
func mapView(_ mapView: MGLMapView, shouldChangeFrom oldCamera: MGLMapCamera, to newCamera: MGLMapCamera, reason: MGLCameraChangeReason) -> Bool {
// we send the userDidPan event only for the reasons that actually will change the map center, and not zoom only / rotations only events.
switch reason {
@@ -203,6 +201,23 @@ extension MapLibreMapView {
}
return true
}
// MARK: Callout
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
false
}
// MARK: Private
private func updateGeolocationUncertainty(location: MGLUserLocation) {
guard let clLocation = location.location, clLocation.horizontalAccuracy >= 0 else {
mapLibreView.geolocationUncertainty = nil
return
}
mapLibreView.geolocationUncertainty = clLocation.horizontalAccuracy
}
}
}