根据经纬度取地址 高德、百度

  系统自带的方法:

//根据经纬度解析成位置  

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


// 百度地图反编译


-(void)mapViewWillStartLocatingUser:(BMKMapView *)mapView{
  NSLog(@"开始定位");
}

/**
 *用户位置更新后,会调用此函数
 *@param mapView 地图View
 *@param userLocation 新的用户位置
 */
-(void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation{
  NSLog(@"latitude--%f,longtitude---%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
  locaLatitude=userLocation.location.coordinate.latitude;//纬度
  locaLongitude=userLocation.location.coordinate.longitude;//精度
  BMKCoordinateRegion region;
  //将定位的点居中显示
  region.center.latitude=locaLatitude;
  region.center.longitude=locaLongitude;
  
       //反地理编码出地理位置
      CLLocationCoordinate2D pt=(CLLocationCoordinate2D){0,0};
      pt=(CLLocationCoordinate2D){locaLatitude,locaLongitude};
      
      BOOL flag=[_search reverseGeocode:pt];
      if (flag) {
        myMapView.showsUserLocation=NO;//不显示自己的位置
        self.btnDone.enabled=YES;
      }
  

  //当前位置标注和地图的比例(注释为可不用)
//	BMKCoordinateSpan spans;
//	spans.latitudeDelta=0.01;
//	spans.longitudeDelta=0.01;
//	region.span=spans;
  myMapView.region=region;
}

在使用  [_search reverseGeocode:pt] 的时候,会调用它的一个协议方法,也就是下面的方法: 

//反地理编码
-(void)onGetAddrResult:(BMKAddrInfo *)result errorCode:(int)error{
  if (error==0) {
    BMKPointAnnotation *item=[[BMKPointAnnotation alloc] init];
    item.coordinate=result.geoPt;//地理坐标
    item.title=result.strAddr;//地理名称
    [myMapView addAnnotation:item];
    myMapView.centerCoordinate=result.geoPt;
    
    self.lalAddress.text=[result.strAddr stringByReplacingOccurrencesOfString:@"-" withString:@""];
    if (![self.lalAddress.text isEqualToString:@""]) {
      strProvince=result.addressComponent.province;//省份
      strCity=result.addressComponent.city;//城市
      strDistrict=result.addressComponent.district;//地区
    }
//		CLGeocoder *geocoder=[[CLGeocoder alloc] init];
//		CLGeocodeCompletionHandler handle=^(NSArray *palce,NSError *error){
//			for (CLPlacemark *placemark in palce) {
//				NSLog(@"%@1-%@2-%@3-%@4-%@5-%@6-%@7-%@8-%@9-%@10-%@11-%@12",placemark.name,placemark.thoroughfare,placemark.subThoroughfare,placemark.locality,placemark.subLocality,placemark.administrativeArea,placemark.postalCode,placemark.ISOcountryCode,placemark.country,placemark.inlandWater,placemark.ocean,placemark.areasOfInterest);
//				break;
//			}
//		};
//		CLLocation *loc = [[CLLocation alloc] initWithLatitude:locaLatitude longitude:locaLongitude];
//		[geocoder reverseGeocodeLocation:loc completionHandler:handle];
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值