【发布时间】:2014-05-19 12:00:19
【问题描述】:
我需要获取用户的纬度和经度,即使 iOS 中没有互联网设施。
注意:没有互联网、没有蜂窝网络和蜂窝服务。
【问题讨论】:
-
只要给用户发短信,告诉他回复当前的经纬度
标签: ios iphone objective-c gps
我需要获取用户的纬度和经度,即使 iOS 中没有互联网设施。
注意:没有互联网、没有蜂窝网络和蜂窝服务。
【问题讨论】:
标签: ios iphone objective-c gps
在你的@implementation 中添加这些变量:
CLLocationManager *manager;
CLGeocoder *geocoder;
在你看来DidLoad:
manager = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
然后添加这些方法:
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
geolocerror = YES;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
NSLog([NSString stringWithFormat:@"Lat: %.8f", currentLocation.coordinate.latitude]);
NSLog([NSString stringWithFormat:@"Long: %.8f", currentLocation.coordinate.longitude]);
}
}
别忘了在你的框架中添加 CoreLocation。
【讨论】:
核心位置框架可让您确定当前位置或 与设备关联的标题。该框架使用可用的 硬件来确定用户的位置和航向。您使用 这个框架中的类和协议来配置和调度 传递位置和航向事件。你也可以用它来定义 地理区域并监控用户何时跨越边界 那些地区。在 iOS 中,您还可以在蓝牙周围定义一个区域 信标
.
【讨论】: