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

来源:互联网 发布:55开淘宝店地址服装 编辑:程序博客网 时间:2024/05/17 01:02

  系统自带的方法:

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

  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