2
我是新的iphone开发,现在我面临着开发一个应用程序的问题,在这个应用程序中,当用户在屏幕上点击两秒钟并获取用户位置名称时,我需要获得坐标(lat,long)但我无法获取用户点击的用户位置名称。那么好心地帮助我呢?如何在iphone中使用mapkit获取位置名称?
我是新的iphone开发,现在我面临着开发一个应用程序的问题,在这个应用程序中,当用户在屏幕上点击两秒钟并获取用户位置名称时,我需要获得坐标(lat,long)但我无法获取用户点击的用户位置名称。那么好心地帮助我呢?如何在iphone中使用mapkit获取位置名称?
在iOS 5+中使用CLGeocoder
及其reverseGeocodeLocation:completionHandler:
方法。
就你而言,你可能最感兴趣的是areasOfInterest
属性。
例子:
CLGeocoder* gc = [[CLGeocoder alloc] init];
double lat, lon; // get these where you will
[gc reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:lat longitude:lon] completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark* place in placemarks) {
if (place.region)
NSLog(@"%@", place.region);
// throroughfare is street name, subThoroughfare is street number
if (place.thoroughfare)
NSLog(@"%@ %@", place.subThoroughfare, place.thoroughfare);
for (NSString* aoi in place.areasOfInterest)
NSLog(@"%@", aoi);
}
}];
你是如何定义的名字吗?地址?商人? –
我需要当前的位置名称,就像if'll点击学校只是说,并作为回应我会得到具体的学校名称,这可能吗?怎么可以? – Aleem