根据经纬度翻译成详细位置的各种方法

首先苹果获取经纬度是

  1. if ([CLLocationManager locationServicesEnabled]) {//判断手机是否可以定位  
  2.     locationManager = [[CLLocationManager alloc] init];//初始化位置管理器  
  3.     [locationManager setDelegate:self];  
  4.     [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];//设置精度  
  5.     locationManager.distanceFilter = 1000.0f;//设置距离筛选器  
  6.     [locationManager startUpdatingLocation];//启动位置管理器  
  7. }  

然后根据其代理获取经纬度

  1. #pragma mark - CLLocationManager Delegate Methods  
  2. - (void)locationManager:(CLLocationManager *)manager  
  3.     didUpdateToLocation:(CLLocation *)newLocation  
  4.            fromLocation:(CLLocation *)oldLocation;  
  5. {  
  6.     location=[newLocation coordinate];//当前经纬度  
  7.     lat=location.latitude;  
  8.     lon=location.longitude;  
  9.       
  10.     MKCoordinateSpan theSpan;  
  11.     theSpan.latitudeDelta=0.01f;  
  12.     theSpan.longitudeDelta=0.01f;  
  13.     theRegion.center=location;//定义地图显示范围  
  14.     theRegion.span=theSpan;  
  15. }  

根据经纬度解析成位置目前有2种。第一个是调用系统的CLGeocoder类的 reverseGeocodeLocation方法

  1. //根据经纬度解析成位置  
  2.    CLGeocoder *geocoder=[[[CLGeocoder alloc]init]autorelease];  
  3.    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemark,NSError *error)  
  4.     {  
  5.         CLPlacemark *mark=[placemark objectAtIndex:0];  
  6.         place.title=@"没有当前位置的详细信息";  
  7.         place.subTitle=@"详细信息请点击‘附近’查看";  
  8.         place.title=[NSString stringWithFormat:@"%@%@%@",mark.subLocality,mark.thoroughfare,mark.subThoroughfare];  
  9.         place.subTitle=[NSString stringWithFormat:@"%@",mark.name];//获取subtitle的信息  
  10.         [self.myMapView selectAnnotation:place animated:YES];  
  11.     } ];  

第二种是调用google的api 

----http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true 

网上有人说系统的方法有时候解析不出来位置。第二种google,国内有时候访问不了google服务器,所以都有缺点。

有人建议国内的地图可以使用高德地图(以后摸索下)

PS1:网上有一个比较流行的查找附近功能,是根据google的api搜索的

#define SEARCH_GOOGLE @"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=1000&types=%@&sensor=true&key=AIzaSyALaqx0MfPsp2aldbZbzEQAq64SwgQfZ0c"

调用的话就是这样

 jsonString = [NSString stringWithFormat:SEARCH_GOOGLE,location.coordinate.latitude,location.coordinate.longitude,@"food"];

 jsonString = [NSString stringWithFormat:SEARCH_GOOGLE,location.coordinate.latitude,location.coordinate.longitude,@"bus_station"];

jsonString = [NSString stringWithFormat:SEARCH_GOOGLE,location.coordinate.latitude,location.coordinate.longitude,@"hospital"];

PS2:有个功能,如果长时间按住地图上某个地方,如何获取其经纬度,进而对其显示位置呢?

----

  1. //开始点击长按,不然会执行2次。  
  2. if (sender.state==UIGestureRecognizerStateBegan) {  
  3.     //isLongPress=YES;  
  4.     CGPoint touchPoint=[sender locationInView:self.myMapView];  
  5.     CLLocationCoordinate2D touchCoordinate=[self.myMapView convertPoint:touchPoint toCoordinateFromView:self.myMapView];//将触摸点转换经纬度  
  6.     //反向解析长按时的大头针的信息  
  7.     location =[[CLLocation alloc]initWithLatitude:touchCoordinate.latitude longitude:touchCoordinate.longitude];  
原文地址:https://www.cnblogs.com/zhaoguowen/p/4186308.html