2

Core Location Services のローカリゼーション API に問題があります。位置情報サービスへの許可を要求するプロンプトが表示されます。[許可] をクリックして [設定] に移動すると、アプリにアクセス許可がないことがわかります。

これは私の GeoUtility クラスの私のコードです:

CLGeocoder *reverseGeocoder = [[CLGeocoder alloc] init];

CLLocationManager *lm = [[CLLocationManager alloc] init];

[lm setPurpose:@"Need to verify your region"];
[lm startUpdatingLocation];

viewDidAppear の viewController によってトリガーされます

location-servicesまた、plist ファイルの Required Devices Capabilites の下に追加しました。

4

1 に答える 1

0

CoreLocation.framework と MapKit.framework を追加

.h で

#import <MapKit/MapKit.h>

CLLocationManager *locationManager;
CLGeocoder *geocoder;

ビューで読み込みました

- (void)viewDidLoad
{
    locationManager = [[CLLocationManager alloc] init];
        geocoder = [[CLGeocoder alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
}

それから

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocation *currentLocation = newLocation;
    if (currentLocation != nil) {
        LongitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.longitude];
        LatitudeLbl.text = [NSString stringWithFormat:@"%.8f",currentLocation.coordinate.latitude];
    }


[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error == nil && [placemarks count] > 0) {
            placemark = [placemarks lastObject];
            NSString *addresstemp2 = [[NSString alloc] init];
            NSString *subThoroughfare2 = [NSString stringWithFormat:@"%@",placemark.subThoroughfare];

            NSString *thoroughfare2 = [NSString stringWithFormat:@"%@",placemark.thoroughfare];
            NSString *postalCode2 = [NSString stringWithFormat:@"%@",placemark.postalCode];
            NSString *locality2 = [NSString stringWithFormat:@"%@",placemark.locality];
            NSString *administrativeArea2 = [NSString stringWithFormat:@"%@",placemark.administrativeArea];
            NSString *country2 = [NSString stringWithFormat:@"%@",placemark.country];

            if (![subThoroughfare2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@",subThoroughfare2];
            }
            if (![thoroughfare2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,thoroughfare2];
            }
            if (![postalCode2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,postalCode2];
            }
            if (![locality2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,locality2];
            }
            if (![administrativeArea2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@ %@ \n",addresstemp2,administrativeArea2];
            } 
            if (![country2 isEqualToString:@"(null)"]) {
                addresstemp2 = [NSString stringWithFormat:@"%@ %@",addresstemp2,country2];
            }
            AddressLbl.text = [[NSString alloc] initWithString:addresstemp2];
            [AddressLbl sizeToFit];

            [locationManager stopUpdatingLocation];
} else {
        }
    } ];
}

また、シミュレーターの設定を変更して、設定に移動し、ロケーションサービスを選択してオンに変更します。see down は、オフの場合はアプリケーション名であり、次にオンに変更します

于 2013-03-07T11:51:29.963 に答える