SORU
11 Kasım 2010, PERŞEMBE


Nasıl iOS kullanıcının geçerli konum alabilir miyim

Nasıl iOS kullanıcının geçerli konumu alabilir miyim?

CEVAP
4 Temmuz 2012, ÇARŞAMBA


RedBlueThing cevabı çok iyi benim için çalıştı. Burada nasıl yaptığımı bazı örnek kod.

Başlık

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface yourController : UIViewController <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}

@end

MainFile

Init yöntemi

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

Geri arama fonksiyonu

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
    NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}

iOS 6

İOS 6 temsilci işlevi bulunmamıştı. Yeni temsilci

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

Yeni pozisyon almak için bu nedenle

[locations lastObject]

iOS 8

İOS 8'de izni açıkça konumunu güncelleştirmek için başlamadan önce istenmesi gerekir

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    [self.locationManager requestWhenInUseAuthorization];

[locationManager startUpdatingLocation];

Ayrıca uygulamanın Bilgi için NSLocationAlwaysUsageDescription NSLocationWhenInUseUsageDescription anahtarlar için bir dize eklemek.plıst. Aksi takdirde startUpdatingLocation çağrıları gözardı edilecek ve temsilci herhangi bir geri almaz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Curso Online Gratuito

    Curso Online

    4 Aralık 2011
  • KIT KAT

    KIT KAT

    3 EKİM 2005
  • PorterRobinsonVEVO

    PorterRobins

    11 Kasım 2013