要想实现通过经纬度获取地址名称,或者通过地址名称获得经纬度,我们要用到一下几个类:
CLLocation CLGrocoder CLPlacemark
经纬度转换成地址名称:
CLLocation *location = [[CLLocation alloc] initWithLatitude:+38.4112810 longitude:-122.8409780]; self.myGeocoder = [[CLGeocoder alloc] init]; [self.myGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError * error){ //placemarks返回的是该经纬度对应的一些地理名称,其中的每个对象类型都是CLPlacemark,可以将其一一取出进行使用 }];
地址名称转换成经纬度:
NSString *oreillyAddress = @"1005 Gravenstein Highway North, Sebastopol, CA 95472, USA"; self.myGeocoder = [[CLGeocoder alloc] init]; [self.myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) { //placemarks返回的是该地址对应的一系列坐标点,类型是CLPlacemark,通过.location.coordinate获得其坐标点 }];
浙公网安备 33010602011771号