Получение UserLocation координат с MapKit

голоса
5

Я использую MapKit в моем приложении и disaply местоположение пользователя с


[mapview setShowUserLocation:YES];

Я хочу, чтобы установить region.center.latitude и region.center.longitude с координатой userLocation, как это сделать?

Задан 01/02/2010 в 11:34
источник пользователем
На других языках...                            


5 ответов

голоса
10

Вот мой ответ, я пытаюсь что-то подобное, и его работы:


//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]; }
Ответил 10/03/2010 в 11:43
источник пользователем

голоса
6

Намного легче:

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
Ответил 15/08/2012 в 14:52
источник пользователем

голоса
2

По какой-то причине, это не работает для меня. Он берет меня к координатам (0.0000, 0.0000). Ниже мой код, если у вас есть шанс проверить это. Спасибо за помощь!

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];

region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self];
Ответил 20/12/2010 в 09:47
источник пользователем

голоса
1

Я думаю , что это ответ на ваш вопрос: Возвращение MapKit Userlocation Координаты

(использует mapView.userLocation.location.coordinate.latitudeи mapView.userLocation.location.coordinate.longitude properties)

а затем вводить эти координаты в

-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated

ваш экземпляр MKMapView.

Ответил 01/02/2010 в 11:41
источник пользователем

голоса
0

Использование делегата:

  1. Добавить MapKit делегат: MKMapViewDelegate
  2. Достичь метод: MapView didUpdateUserLocation
    -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate,
            500, 500);
        [mapView setRegion:region animated:YES];
    }
    

Без делегата:

[self.mapView setuserTrackingMode:MKUserTrackingModeFollow];
Ответил 23/05/2019 в 04:03
источник пользователем

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more