How to get location name using mapkit in iphone?

旧巷老猫 提交于 2019-12-07 21:49:00

问题


I am new in iphone development and right now i am facing problem for developing developing an application in which i need to get coordinate(lat, long) when user tapped on screen for two second and also get user location name,i got coordinate but i am unable to get user location name on which user tapped. so kindly help me on that?


回答1:


In iOS 5+ use CLGeocoder and its reverseGeocodeLocation:completionHandler: method.

In your case, you're probably most interested in the areasOfInterest property.

Example:

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 );
    }
}];


来源:https://stackoverflow.com/questions/7914900/how-to-get-location-name-using-mapkit-in-iphone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!