Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve UserLocation Coordinate with MapKit

I"m using MapKit in my application and disaply the user location with


[mapview setShowUserLocation:YES];

I want to set the region.center.latitude and region.center.longitude with the coordinate of the userLocation, how to do it?

like image 857
ludo Avatar asked Feb 01 '10 10:02

ludo


People also ask

How do I find my current location SwiftUI?

Next, you create some kind of ObservableObject that is able to request the user's location on demand. This needs to create a CLLocationManager and call its requestLocation() method on demand. You can then put that inside a SwiftUI view showing a location button.

What is CLLocation in Swift?

A CLLocation object contains the geographical location and altitude of a device, along with values indicating the accuracy of those measurements and when they were collected. In iOS, a location object also contains course information — that is, the speed and heading in which the device was moving.

How do I use maps in SwiftUI?

Displaying a Map View in SwiftUI To work with Map , you need to provide a binding of MKCoordinateRegion that keeps track of the region to display on the map. The MKCoordinateRegion structure lets you specify a rectangular geographic region centered around a specific latitude and longitude.


1 Answers

Here is my answer, I try something like that and its working:


//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation  {
CLLocationCoordinate2D loc = [newLocation coordinate]; [maptView setCenterCoordiante:loc]; }
like image 197
ludo Avatar answered Oct 06 '22 03:10

ludo