我在我的应用程序中使用位置管理器,我的位置不准确.我使用下面的代码来获取位置
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
Run Code Online (Sandbox Code Playgroud)
在didupdatetolocation方法我正在使用此代码.
LatitudeData = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.latitude];
LongitudeData = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.longitude];
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
[self insertNewLocationInDataBase];
Run Code Online (Sandbox Code Playgroud)
我需要设置distancefilter吗?我如何获得准确的位置?我想获得准确的位置然后将在数据库中插入位置.
我已经通过核心位置制作了一个单独的类来获取位置.现在我的问题是我想知道位置何时更新.我想在此使用委托而不是通知.我知道我可以发布通知.但我根本不想使用通知.有没有其他方法可以做到这一点,或者只有我的解决方案是NSNotifications.
这是一些代码
//Initilizer
+ (LocationController *)locationManager;
//How I want to be informed using delegates
id<locationControllerDelegate> delegate;
//Instead what I am being forced to use since I dont know how to use delegates with singleton :(
[[NSNotificationCenter defaultCenter] postNotificationName:@"updated" object:nil];
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑1:
在典型的委托和简单的课程中,我们喜欢这样
someClass *somecls = [[someClass alloc] init];
somecls.delegate = self
Run Code Online (Sandbox Code Playgroud)
但在单身人士中,我们不做任何类的实例
[[LocationController locationmanager] startUpdateLocation];
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下我将如何设置单例类的委托
我使用以下代码从CLGeocoder接收地标,我想在同一个viewcontroller上只显示另一个textview中的城市.我如何从这个阵列中解析出这座城市?它不是NSDictionary或任何东西,所以我不知道该怎么做.
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
NSLog(@"Received placemarks: %@", placemarks);
}];
Run Code Online (Sandbox Code Playgroud)
我给定地标的日志如下:
<__ NSArrayM 0x1a0b3810>(937-961 Sunnyvale Saratoga Rd,937-961 Sunnyvale Saratoga Rd,Sunnyvale,CA 94087,United States @ + + 37.35984860,-122.03235910> +/- 100.00m)
要么
<__ NSArrayM 0x19576ac0>(5600 Van Nuys Blvd,5600 Van Nuys Blvd,Van Nuys,CA 91401-4602,United States @ <+ 34.17257000,-118.44794450> +/- 100.00m,region(identifier <+ 34.17257001,-118.44794464> radius 57.64)<+ 34.17257001,-118.44794464>半径57.64m)
我如何才能将Sunnyvale或Van Nuys的部分显示为字符串?
我的问题基本上是 - 如何修改iBeacon的默认设置,如major,minor和RSSI?
我正在尝试使用实现一个实例MKMapView,用于CoreLocation跟踪用户位置,然后放大它们的位置.
我只想在我处于前台时跟踪用户的位置.由于我的应用程序是针对iOS8的,因此我有一个密钥的plist条目NSLocationWhenInUseUsageDescription.
当我第一次运行应用程序时,应用程序会相应地询问它是否可以访问我的位置.单击"允许"后,我会从Xcode收到以下警告:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
......这实际上有点令人困惑,正如我在requestWhenInUseAuthorization下面的代码中可以看到的那样:
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@property(nonatomic, retain) CLLocationManager *locationManager;
@end
@implementation MapView
- (void)viewDidLoad {
[super viewDidLoad];
[self locationManager];
[self updateLocation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
self.locationManager = nil;
}
- (CLLocationManager *)locationManager {
//We only want to get the location when the app is in the …Run Code Online (Sandbox Code Playgroud) 在Android中有一个方法叫做getLastLocation()允许你保存最后一个位置,如果GPS被禁用,例如,是否有任何功能在Swift中有效?
是否可以比较互联网GPS和真实GPS的结果之间的准确性?
注意:-(集成AppleMap,不兼容GoogleMap)
我已经完成以下工作:
我的要求:
当用户朝不同方向停留在同一位置(或不同位置)时,引脚(在当前位置)应自动指向用户指向的方向。
例如:如果划船显示在用户位置位置,并且指向北,但是如果用户向西移动,则划船(用户位置图钉)也应指向该方向。
尝试使用以下代码:
//MARK:Change Direction Methods
func angle(fromCoordinate first: CLLocationCoordinate2D, toCoordinate second: CLLocationCoordinate2D) -> Float {
let deltaLongitude = second.longitude - first.longitude
let deltaLatitude = second.latitude - first.latitude
let angle = (.pi * 0.5) - atan(deltaLatitude / deltaLongitude)
if deltaLongitude > 0 {
return Float(angle)
}
else if deltaLongitude < 0 {
return Float(angle) + .pi
}
else if deltaLatitude < 0 {
return .pi
} …Run Code Online (Sandbox Code Playgroud) 在我的iOS应用程序中,我需要获取用户当前的国家/地区.
我知道我可以使用它CLLocation来检索位置然后reverseGeocodeLocation获取国家/地区,但如果用户未授权我的应用获取其位置,则无法使用.我也许可以用(Locale.current as NSLocale).object(forKey: NSLocale.Key.countryCode); 但是我想知道countryCode是在用户旅行时更改还是仅在他手动更改设置时更改?
是否可以从当前的运营商运营商处检索此信息?
在iOS 11以后,我们遵循Apple的这些说明:
您需要在应用程序的Info.plist文件中包含NSLocationWhenInUseUsageDescription和NSLocationAlwaysAndWhenInUsageDescription键.(如果您的应用程序支持iOS 10及更早版本,则还需要NSLocationAlwaysUsageDescription键.)如果这些键不存在,则授权请求会立即失败.
当提示用户启用位置跟踪时,这会显示"始终"和"使用中"选项.
但是,我们只想显示"始终"选项.这可能吗?
core-location ×10
ios ×5
objective-c ×4
mkmapview ×3
iphone ×2
swift ×2
clgeocoder ×1
cocoa-touch ×1
ibeacon ×1
ios4 ×1
location ×1
parsing ×1
swift3 ×1
uikit ×1
xcode ×1