如何使用mapkit获取当前位置的邮政编码,我没有找到任何用于在文档中获取此API的API。我使用了CLLocationManager的坐标,取样,水平,垂直,球场和速度参数,但未能获得邮政编码。获取当前位置的邮政编码 - iPhone SDK
任何人都可以给我API或示例代码来完成它。
是否有可能使用iphone中的当前位置获取邮政编码?
如何使用mapkit获取当前位置的邮政编码,我没有找到任何用于在文档中获取此API的API。我使用了CLLocationManager的坐标,取样,水平,垂直,球场和速度参数,但未能获得邮政编码。获取当前位置的邮政编码 - iPhone SDK
任何人都可以给我API或示例代码来完成它。
是否有可能使用iphone中的当前位置获取邮政编码?
您可以使用纬度和经度创建一个MKPlacemark object,其中包括邮政编码。
Here是一个示例,显示如何做到这一点。
反向地理编码在iPhone:
首先添加<MobileCoreServices/MobileCoreServices.h>
框架。
-(void)CurrentLocationIdentifier
{
//---- For getting current gps location
CLLocationManager *locationManager;
CLLocation *currentLocation;
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
使用GPS位置获取地点详情的反向地理编码。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"\nCurrent Location Detected\n");
NSLog(@"placemark %@",placemark);
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSString *Zipcode = [[NSString alloc]initWithString:placemark.postalCode];
NSLog(@"%@",Zipcode);
}
else
{
NSLog(@"Geocode failed with error %@", error); // Error handling must required
}
}];
}
有关详细信息,从GPS获得:
placemark.region
placemark.country
placemark.locality
placemark.name
placemark.ocean
placemark.postalCode
placemark.subLocality
placemark.location
非常感谢尼克,我测试了它的工作,感谢你的帮助。 – 2011-04-30 11:15:03