Tidy up some location things

This commit is contained in:
Garth Vander Houwen 2023-04-08 00:34:39 -07:00
parent ca4354d853
commit f9cf71ad4e
11 changed files with 109 additions and 93 deletions

View file

@ -39,7 +39,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
.filter { $0.latest == true }
.sorted { $0.nodePosition?.num ?? 0 > $1.nodePosition?.num ?? -1 }
let span = MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003)
let center = (latest.count > 0 && userTrackingMode == MKUserTrackingMode.none) ? latest[0].coordinate : LocationHelper.currentLocation
let center = (latest.count > 0 && userTrackingMode == MKUserTrackingMode.none) ? latest[0].coordinate : LocationHelper.currentLocation.coordinate
let region = MKCoordinateRegion(center: center, span: span)
mapView.addAnnotations(showNodeHistory ? positions : latest)
mapView.setRegion(region, animated: true)
@ -263,7 +263,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
annotationView.glyphImage = UIImage(systemName: "flipphone")
}
if LocationHelper.currentLocation.distance(from: LocationHelper.DefaultLocation) > 0.0 {
let metersAway = positionAnnotation.coordinate.distance(from: LocationHelper.currentLocation)
let metersAway = positionAnnotation.coordinate.distance(from: LocationHelper.currentLocation.coordinate)
subtitle.text! += NSLocalizedString("distance", comment: "") + ": \(distanceFormatter.string(fromDistance: Double(metersAway))) \n"
}
subtitle.text! += positionAnnotation.time?.formatted() ?? "Unknown \n"
@ -296,7 +296,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
subtitle.text = ""
}
if LocationHelper.currentLocation.distance(from: LocationHelper.DefaultLocation) > 0.0 {
let metersAway = waypointAnnotation.coordinate.distance(from: LocationHelper.currentLocation)
let metersAway = waypointAnnotation.coordinate.distance(from: LocationHelper.currentLocation.coordinate)
let distanceFormatter = MKDistanceFormatter()
subtitle.text! += NSLocalizedString("distance", comment: "") + ": \(distanceFormatter.string(fromDistance: Double(metersAway))) \n"
}