iOS 实时定位功能
来源:互联网 发布:无线串口软件 编辑:程序博客网 时间:2024/05/14 17:05
<pre name="code" class="objc">using namespace std; #import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @class CLLocationManager; @class MKReverseGeocoder; @interface GpsInfo: NSObject<MKReverseGeocoderDelegate, CLLocationManagerDelegate> { @private CLLocationManager* locationMgr; MKReverseGeocoder* reverseGeocoder;// iso 5.0以下SDK版本使用 //CLGeocoder* clGeocoder;// iso 5.0及5.0以上SDK版本使用 } @property (nonatomic, retain) CLLocationManager* locationMgr; @property (nonatomic, retain) MKReverseGeocoder* reverseGeocoder; //@property (nonatomic, retain) CLGeocoder* clGeocoder;// iso 5.0及5.0以上SDK版本使用 // location detect - (void)UpdateLocationLatLng; @end
<pre name="code" class="objc">#import "GpsInfo.h" using namespace std;// this line is to fix "isinf" was not declared in this scop problem #import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h> #import "Util.h" @implementation GpsInfo @synthesize locationMgr; @synthesize reverseGeocoder; //@synthesize clGeocoder; - (id)init { self = [super init]; if (self) { locationMgr = nil; reverseGeocoder = nil; [self UpdateLocationLatLng]; } return self; } - (void)dealloc { [locationMgr release]; locationMgr = nil; [reverseGeocoder release] reverseGeocoder = nil; //[clGeocoder release]; //clGeocoder = nil; [super dealloc]; } -(void)UpdateLocationLatLng { if (locationMgr == nil) { locationMgr = [[CLLocationManager alloc] init]; locationMgr.delegate = self; locationMgr.desiredAccuracy = kCLLocationAccuracyBest; } [locationMgr startUpdatingLocation]; } #pragma mark - get Placemark // iso 5.0以下SDK使用 - (void)startedReverseGeoderWithLatitude: (double)latitude longitude: (double)longitude { CLLocationCoordinate2D coordinate2D; coordinate2D.latitude = latitude; coordinate2D.longitude = longitude; if (reverseGeocoder == nil) { reverseGeocoder = [MKReverseGeocoder alloc]; } reverseGeocoder = [reverseGeocoder initWithCoordinate:coordinate2D]; reverseGeocoder.delegate = self; [reverseGeocoder start]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"Geocoder error!"); } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { NSLog(@"GPS Info: country:%@, locality:%@, subLocality:%@, thoroughfare:%@, subThoroughfare:%@", placemark.country, placemark.locality, placemark.subLocality, placemark.thoroughfare, placemark.subThoroughfare); if (m_gpsInfoLocal != nil) { if (placemark.country != nil) {}; else {}; if (placemark.locality != nil) {}; else {}; if (placemark.subLocality != nil) {}; else {}; if (placemark.thoroughfare != nil) {}; else {}; if (placemark.subThoroughfare != nil) {}; else {}; } } /* ! This project use DeploymentTarget for 4.3 // iso 5.0及5.0以上SDK版本使用 - (void)locationAddressWithCLLocation:(CLLocation*)locationGps { if (self.clGeocoder == nil) self.clGeocoder = [[CLGeocoder alloc] init]; [self.clGeocoder reverseGeocodeLocation:locationGps completionHandler:^(NSArray* placemarks, NSError* error) { MKPlacemark* placemark = [placemarks objectAtIndex:0]; }]; } */ #pragma mark - location Delegate - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"Location error!"); } // iso 5.0及5.0以下SDK使用 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (!newLocation) { [self locationManager:manager didFailWithError:NULL]; return; } /* ! signbit 需要引入库framework libSystem.B.dylib,暂时注掉。 // horizontalAccuracy,用来得到水平上的精确度,它的大小就是定位精度的半径,单位为米。如果值为-1,则说明此定位不可信。 if (signbit(newLocation.horizontalAccuracy)) { [self locationManager:manager didFailWithError:NULL]; return; } */ [manager stopUpdatingLocation];// 用完就停,减少耗电 NSLog(@"current location: %f, %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude); // 解析坐标获得城市信息 /*这个项目使用4.3的SDK if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) { [self locationAddressWithCLLocation:newLocation]; } else { [self startedReverseGeoderWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]; } */ [self startedReverseGeoderWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]; } @end
0 0
- iOS 实时定位功能
- iOS Location 定位功能
- 定位功能iOS SDK
- iOS定位功能实现
- 、简单实现百度地图实时定位功能
- IOS Core Location 定位功能
- iOS定位与地图功能
- iOS 定位功能的实现
- ios之Core Location定位功能
- iOS开发中实现后台定位功能
- iOS地图定位使用几个小功能
- iOS百度地图定位功能iOS8+
- iOS中定位功能的实现
- ios系统地图的定位功能
- iOS 自带定位功能CoreLocation
- iOS地图定位使用几个小功能
- iOS地图定位小功能(上)
- iOS 设置模拟器支持定位功能
- iOS 判断GPS是否开启
- mysql 解决数据库连接变慢
- cocos2dx之商店源码
- Linux 下的 CONFIG_OF 选项
- Oracle中merge into的使用
- iOS 实时定位功能
- 属性的小问题
- java.lang.IllegalArgumentException:No view found for id for fragment 的解决
- Unity如何在Android上弹出通知消息
- hdu 5335 Walk Out 搜索+贪心
- UserDefault
- Thinkphp 配置404页面
- Ubuntu终端Terminal常用快捷键
- mongodb源码分析