Tuesday, February 20, 2024
HomeiOS Developmentios - Find out how to make MapKit map observe person location...

ios – Find out how to make MapKit map observe person location easily? (just like Apple Maps)


I’m attempting to make a SwiftUI map app utilizing MapKit and CoreLocation. There may be an possibility for the map to maneuver with the person as his location adjustments (transfer because the blue marker strikes).

My drawback is that as the placement updates (each half second or so) the map jerks from the earlier location to the subsequent one (there’s a pace up and cease) as a substitute of a linear motion (like how it’s in Apple Maps if the person strikes round).

Right here is the code for my View:

Map(place: $place) {
    UserAnnotation()
}
.onReceive(locationManager.$place, carry out: { newValue in
    withAnimation(.easy) {
        place = newValue
    }
})

The place is a printed worth coming from my LocationManager which updates within the following code:

func locationManager(_ supervisor: CLLocationManager, didUpdateLocations areas: [CLLocation]) {
        guard let location = areas.final else { return }
        self.place = .area(MKCoordinateRegion(middle: CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)))
    }

I attempted utilizing withAnimation nevertheless it simply makes it animate between one worth and one other, however it’s nonetheless not linear all through a number of worth adjustments.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments