苹果的定位服务编码

 

用到的类 CLGeocoder,用到的函数geocodeAddressString

 

上代码

- (void)encodeAddressToCoordinate :(NSString*)address

{

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

    [encoder geocodeAddressString:address completionHandler:^(NSArray *placemarks,NSError *error){

    

        CLPlacemark *placemark = placemarks[0];//进行编码返回的是一个CLPlacemark的数组

        CLLocationCoordinate2D coordinate = placemark.location.coordinate;

        

        

        NSString *strCoordinate = [NSString stringWithFormat:@"经度:%3.5f\n纬度%3.5f",coordinate.latitude,coordinate.longitude];

        NSDictionary *addressDictionary = placemark.addressDictionary;

        NSString *address = [addressDictionary objectForKey:(NSString*)kABPersonAddressStreetKey];

        NSString *city = [addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey];

        NSString *kstate = [addressDictionary objectForKey:(NSString*)kABPersonAddressStateKey];

        

        NSString *final = [NSString stringWithFormat:@"%@\n%@\n%@\n%@",strCoordinate,kstate,city,address];

        NSLog(@"%@",final);

    

    }];

 

}

你可能感兴趣的:(编码)