首页 > 网站 > 建站经验 > 正文

iOS8 根据经纬度显_示地名

2019-11-02 14:36:46
字体:
来源:转载
供稿:网友

   我们很多时候做项目的时候都选用通过手机获取定位,然后传数据给后台,这是iOS8根据经纬度显示地名的demo

  //1.导入框架

  //

  // NearByViewController.m

  // nearDemo

  //

  // Created by apple on 14/12/5.

  // Copyright (c) 2014年 youdianshang. All rights reserved.

  //

  #import

  #import

  @interface NearByViewController ()

  {

  NSUserDefaults *defaluts;

  NSString * jingduStr;

  NSString *weiduStr;

  NSString *LocationAddress;

  }

  @property(nonatomic,retain)CLLocationManager *locationManager;

  @property(strong,nonatomic)UILabel *positionLabel;

  /*

  经纬度相关设置

  */

  -(void)getLocationAll

  {

  self.locationManager = [[CLLocationManageralloc]init];

  _locationManager.delegate =self;

  _locationManager.desiredAccuracy =kCLLocationAccuracyBest;

  _locationManager.distanceFilter =10;

  [_locationManagerrequestAlwaysAuthorization];//添加这句

  [_locationManagerstartUpdatingLocation];

  }

  /*

  //通过经纬度得到当前地理位置

  -(void)change{

  defaluts=[NSUserDefaultsstandardUserDefaults];

  CLLocationCoordinate2D coordinate;

  coordinate.latitude = [[NSStringstringWithFormat:@"%@",jingduStr]floatValue];

  coordinate.longitude = [[NSStringstringWithFormat:@"%@",weiduStr]floatValue];

  CLLocation *newLocation=[[CLLocationalloc]initWithLatitude:coordinate.latitudelongitude: coordinate.longitude];

  CLGeocoder *geocoder=[[CLGeocoderalloc] init];

  [geocoder reverseGeocodeLocation:newLocationcompletionHandler:^(NSArray* placemarks,NS

搞笑gif动态图片[www.62-6.com/1/gaoxiaogif/]
Error* error)

  {

  MKPlacemark*placemark = [placemarks objectAtIndex:0];

  LocationAddress = [NSStringstringWithFormat:@"%@%@%@%@", placemark.locality, placemark.subLocality,placemark.thoroughfare, placemark.subThoroughfare];

  [defaluts setObject:LocationAddress forKey:@"address"];

  NSLog(@"终极目标:1:%@2:%@3:%@4:%@", placemark.locality, placemark.subLocality,placemark.thoroughfare,placemark.subThoroughfare);

  }];

  #pragma mark--实现CLLocationManagerDelegate的代理方法,获取地理位置(镔)===========================================================================

  //(1)获取到位置数据,返回的是一个CLLocation的数组,一般使用其中的一个

  - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

  {

  CLLocation *currLocation = [locations lastObject];

  NSLog(@"经度=%f纬度=%f高度=%f", currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);

  jingduStr =[NSStringstringWithFormat:@"%f", currLocation.coordinate.latitude];

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表