简体   繁体   中英

Get Location information Using CLPlaceMark And CLGeocoder

我已经在iOS 6的地图上使用ClLocationCoordinate2D动态绘制了两个地点之间的路线,有人可以帮我使用CLPlacemark和CLGeocoder获取地点名称,因为反向地理编码器已在iOS 6中弃用。

you can get information like bellow with its Delegate method..

UPDATE:

First Define this variable in .h file like bellow..

NSString *postcode,*locationName;

and use it in bellow method...

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        for (CLPlacemark * placemark in placemarks) {
            postcode = [placemark postalCode];
            [postcode retain];
            locationName = [placemark name];
            [locationName retain];

            NSLog(@"\n placemark %@",placemarks);
        }    
    }];
    [geoCoder release];
    NSLog(@"\n Location Name ==> %@  ----> GotPostCode:%@",locationName,postcode);
}

here you can also use other property of CLGeocoder like locality , location ,etc...

A CLPlacemark object stores placemark data for a given latitude and longitude. Placemark data includes information such as the country, state, city, and street address associated with the specified coordinate.

Check Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM