最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS開(kāi)發(fā)筆記整理49之詳解定位CLLocation

 更新時(shí)間:2015年11月27日 15:14:22   作者:Mr.林的博客  
在項(xiàng)目功能中有一個(gè)定位CLLocation的需求,遇到了一些知識(shí)難點(diǎn),經(jīng)過(guò)各位大俠的幫助,問(wèn)題解決,特此分享供大家學(xué)習(xí),希望大家共同學(xué)習(xí)進(jìn)步

在項(xiàng)目功能中有一個(gè)定位CLLocation的需求,遇到了一些知識(shí)難點(diǎn),經(jīng)過(guò)各位大俠的幫助,問(wèn)題解決,特此分享供大家學(xué)習(xí),希望大家共同學(xué)習(xí)進(jìn)步。

一、簡(jiǎn)單說(shuō)明

1.CLLocationManager

CLLocationManager的常用操作和屬性

開(kāi)始用戶定位- (void)startUpdatingLocation;

停止用戶定位- (void) stopUpdatingLocation;

說(shuō)明:當(dāng)調(diào)用了startUpdatingLocation方法后,就開(kāi)始不斷地定位用戶的位置,中途會(huì)頻繁地調(diào)用代理的下面方法

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

每隔多少米定位一次

  @property(assign, nonatomic) CLLocationDistance distanceFilter;

定位精確度(越精確就越耗電)

  @property(assign, nonatomic) CLLocationAccuracy desiredAccuracy;

使用定位功能,首先要導(dǎo)入框架,遵守CLLocationManagerDelegate協(xié)議,再創(chuàng)建位置管理器CLLocationManager

在iOS8.0后,定位功能需要在info.plist中加入NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription這兩個(gè)NSString類型字段,才能夠使用定位功能

代碼貼出來(lái)與大家共勉,各位看官自行研究

{
  self.locationManager = [[CLLocationManager alloc] init];
  _locationManager.delegate = self;
  if([CLLocationManager locationServicesEnabled] == NO) {
   //  NSLog(@"沒(méi)有GPS服務(wù)");
  }
  //地理位置精確度
  _locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
  //設(shè)置距離篩選器,double類型,只要距離變化多少,就調(diào)用委托代理
  self.locationManager.distanceFilter = kCLDistanceFilterNone; // meters
  [_locationManager requestWhenInUseAuthorization];// 前臺(tái)定位
  [_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
   didUpdateLocations:(NSArray *)locations
{
  NSLog(@"longitude = %f", ((CLLocation *)[locations
                       lastObject]).coordinate.longitude);
  NSLog(@"latitude = %f", ((CLLocation *)[locations lastObject]).coordinate.latitude);
    CGFloat longTI=((CLLocation *)[locations
                    lastObject]).coordinate.longitude;
    CGFloat latTI=((CLLocation *)[locations lastObject]).coordinate.latitude;
    //將經(jīng)度顯示到label上
    _longitudeLabel.text = [NSString stringWithFormat:@"%f",longTI];
    //將緯度現(xiàn)實(shí)到label上
    _latitudeLabel.text = [NSString stringWithFormat:@"%f",latTI];
  // 獲取當(dāng)前所在的城市名
  CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  //根據(jù)經(jīng)緯度反向地理編譯出地址信息
  [geocoder reverseGeocodeLocation:locations.lastObject completionHandler:^(NSArray *array, NSError *error)
   {
     if (array.count > 0)
     {
       CLPlacemark *placemark = [array objectAtIndex:0];
//       //將獲得的所有信息顯示到label上
//       self.location.text = placemark.name;
       //獲取城市
       NSString *city = placemark.locality;
       if (!city) {
         //四大直轄市的城市信息無(wú)法通過(guò)locality獲得,只能通過(guò)獲取省份的方法來(lái)獲得(如果city為空,則可知為直轄市)
         city = placemark.administrativeArea;
       }
      // NSLog(@"city = %@", city);
       _cityName=city;
     }
     else if (error == nil && [array count] == 0)
     {
      // NSLog(@"No results were returned.");
     }
     else if (error != nil)
     {
      // NSLog(@"An error occurred = %@", error);
     }
   }];
  //系統(tǒng)會(huì)一直更新數(shù)據(jù),直到選擇停止更新,因?yàn)槲覀冎恍枰@得一次經(jīng)緯度即可,所以獲取之后就停止更新
  [manager stopUpdatingLocation];
}

以上是關(guān)于腳本之家小編給大家整理的IOS開(kāi)發(fā)之詳解定位CLLocation,后續(xù)還會(huì)持續(xù)更新,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論

苏州市| 桦甸市| 顺昌县| 黎城县| 原阳县| 翼城县| 都匀市| 永善县| 青铜峡市| 壤塘县| 密云县| 邳州市| 开平市| 梁河县| 闵行区| 萨嘎县| 竹山县| 石楼县| 乌什县| 乐东| 东平县| 文水县| 潞西市| 铜鼓县| 辛集市| 舞阳县| 万安县| 乌恰县| 永城市| 土默特右旗| 邵阳市| 临汾市| 库伦旗| 德兴市| 宣威市| 辽中县| 庄浪县| 凯里市| 凤台县| 衡山县| 万山特区|