文档详情

《从零开始学iOS7开发系列3-我的地盘我做主-Cha11》.pdf

发布:2015-10-06约1.06万字共11页下载文档
文本预览下载声明
从零开始学iOS7开发系列3-我的地盘我做主-Cha11 原⽂及⽰例代码来⾃raywenderlich store中的iOS Apprentice 系列3教程,经过翻译和改编。 版权归原作者所有,本系列教程仅供学习参考使⽤,感兴趣的朋友建议购买原英⽂教程教程(The iOS Apprentice Second Edition: Learn iPhone and iPad Programming via Tutorials!)。 购买链接: /store 欢迎回来,在⽕炉边找个位置坐下来吧。 在上⼀课的内容中,我们接触了所谓的reverse geocoding这种神秘⽽⼜⾼⼤上的东⻄。 在实际测试的时候,可能在Simulator上会出⼀些状况,在iPod touch和⾮3G版的iPad上⾯也可能会 有问题。因为iPod touch和⾮3G版的iPad没有GPS ,只能靠Wi-Fi来定位。不过Wi-Fi的精度不够, 个⼈试过在+/-100⽶左右。 到现在为⽌,我们只能在位置信息精度进⼊desireAccuracy的范围内才能停⽌位置信息的更新,⽽ 遗憾的是在iPod 上很难实现这⼀点。因此,在开发基于地理位置的应⽤时,我们必须在各种设备上 进⾏测试。 为了应对上⾯所说的情况,我们需要改善下didUpdateLocations⽅法。 在Xcode 中切换到CurrentLocationViewController.m ,更改didUpdateLocation⽅法如下: -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *newLocation = [locations lastObject]; NSLog(@ 已更新坐标,当前位置:%@,newLocation); if([newLocation.timestamp timeIntervalSinceNow] -5.0){ return; } if(newLocation.horizontalAccuracy 0){ return; } CLLocationDistance distance = MAXFLOAT; if(_location !=nil){ distance = [newLocation distanceFromLocation:_location]; } if(_location == nil || _location.horizontalAccuracy newLocation.horizontalAccuracy){ _lastLocationError = nil; _location = newLocation; [self updateLabels]; if(newLocation.horizontalAccuracy = _locationManager.desiredAccuracy){ NSLog(@*** ⺫标诺森德!成功完成定位); [self stopLocationManager]; [self configureGetButton]; } if(distance 0){ _performingReverseGeocoding = NO; } if(!_performingReverseGeocoding){ NSLog(@*** Going to geocode); _performingReverseGeocoding = YES; [_geocoder reverseGeocodeLocation:_location completionHandler:^(NSArray *placemarks,NSError *
显示全部
相似文档