我正在尝试构建一个iOS应用程序,显示跑步或步行时的总行驶距离.我已经阅读并重新阅读了我能找到的所有文档,但是我无法想出能够给出准确总距离的东西.
与Nike + GPS或RunKeeper相比,我的应用程序始终报告较短的距离.他们一开始会报告相同的情况,但随着我不断前进,我的应用程序与其他正在运行的应用程序的价值逐渐变化.
例如,如果我走了0.3公里(通过我的汽车里程表验证),Nike + GPS和RunKeeper每次报告约.3公里,但我的应用程序将报告〜.13公里.newLocation.horizontalAccuracy始终为5.0或10.0.
这是我正在使用的代码.我错过了一些明显的东西吗 有关如何改进这一点以获得更准确读数的任何想法?
#define kDistanceCalculationInterval 10 // the interval (seconds) at which we calculate the user's distance
#define kNumLocationHistoriesToKeep 5 // the number of locations to store in history so that we can look back at them and determine which is most accurate
#define kValidLocationHistoryDeltaInterval 3 // the maximum valid age in seconds of a location stored in the location history
#define kMinLocationsNeededToUpdateDistance 3 // the number of locations needed in history before we …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,位置服务已启用(来自设置等),我正在使用ALAssetsLibrary从我的设备中读取所有照片.
它在iPhone4 iOS 4.2.1上完美运行,但相同的代码和相同的资产在任何3gs任何iOS(从4.0到4.2.1)上都不能工作.
问题是它总是在3gs上检索无效的CLLocation.
即使在iPhone4上的相同图片(复制到两个设备上)也会返回有效的CLLocation,在3gs上它返回无效!图片图片本身在两台设备上都有效,只有CLLocation无效.我没有任何崩溃,并且代码没有进入任何无效的块,除了无效的CLLocation数据之外它都可以正常工作.
输出相同的资产和相同的代码以及相同的iOS版本(4.2.1):
iPhone4:<+ 51.23816667,-0.57700000> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 19/02/2011 01:59:28格林威治标准时间
3gs:<nan,nan> +/- 0.00m(速度-1.00 mps/course -1.00)@ 2011-02-19 01:20:35 +0000
(注意无效位置上的日期是当前时间)
我得到这样的CLLocation:
CLLocation* location = [asset valueForProperty:ALAssetPropertyLocation];
CLLocationCoordinate2D coord = [location coordinate];
if ( !CLLocationCoordinate2DIsValid(coord) ) return;
Run Code Online (Sandbox Code Playgroud)
在我的viewcontroller DidLoad中调用的ALAssetsLibrary代码看起来像这样(完全标准):
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL)
{
[self myFunction:result withIndex:index];
}
}; …Run Code Online (Sandbox Code Playgroud) 我正在使用位置服务开发iOS应用程序.拥有实验物理学的背景,我想知道究竟horizontalAccuracy在location找到 什么locationManager:didUpdateToLocation:fromLocation:.文档有点稀疏......
我假设精度给出了基于高斯(或泊松?)分布的置信区间.因此,在一定概率下,实际位置在半径为的圆内horizontalAccuracy,但也可以在该区域之外.那么问题是:这个概率有多大?如果horizontalAccuracy对应于1σ,我有68%的概率在该圆圈内horizontalAccuracy,但相反地看,在近三分之一的情况下,实际位置将在该区域之外.因此,在某些情况下,我宁愿使用2σ(2*horizontalAccuracy)甚至3σ(3*horizontalAccuracy)来计算.
简而言之:某处是否有任何迹象,哪个置信区间horizontalAccuracy有?
评论所有回答"Apple说它在其中"的人:嗯 - 测量结果不准确.它必须具有一定程度的不确定性.如果您经常重复测量,您将获得结果分布 - 可能是高斯分布.该高斯具有一定的宽度,其对应于测量的不确定性水平.更频繁地测量位置将减少不确定性并因此提高准确度,但永远不会给出明确的间隔,其中保证实际位置.您将只获得概率.但如果准确度是3sigma,我们有99.7% - 这是接近确定的.简而言之 - 我怀疑Apple的文档.
我收到addressString后调用此函数:
[[self geocoder] geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks onlyObject];
block(placemark, self.name, error);
}
}];
Run Code Online (Sandbox Code Playgroud)
它返回地标为nil,错误为:Error Domain = kCLErrorDomain Code = 8"操作无法完成.(kCLErrorDomain error 8.)"
我的地址字符串是从这个字典中为placeDictionary [@"formatted_address"]检索的:
placeDictionary =
{
"address_components" = (
{
"long_name" = "Palolem Beach";
"short_name" = "Palolem Beach";
types = (
"natural_feature",
establishment
);
},
{
"long_name" = "South Goa";
"short_name" = "South Goa";
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = …Run Code Online (Sandbox Code Playgroud) 这是我在AppDelegate类中的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = 1000; // 1 Km
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
这是我在AppDelegate类中的委托方法
//This is the delegate method for CoreLocation
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)
它工作在3.0,3.1,3.1.3,但它不适用于4.0模拟器和设备.
是什么原因 ?
使用Firebase作为我的后端,我有一系列的经纬度坐标字符串,如何将它们转换为CLLocationCoordinate2D以便我可以使用它们进行注释?以下是每次更新时从Firebase获取信息的代码
var UpdateRef = Firebase(url:"https://ici.firebaseio.com/users")
UpdateRef.observeEventType(.ChildChanged, withBlock: { (snapshot) in
let MomentaryLatitude = snapshot.value["latitude"] as? String
let MomentaryLongitude = snapshot.value["longitude"] as? String
let ID = snapshot.value["ID"] as? String
println("\(MomentaryLatitude)")
var Coordinates = CLLocationCoordinate2D(latitude: MomentaryLatitude as
CLLocationDegrees, longitude: MomentaryLongitude as CLLocationDegrees)
}
Run Code Online (Sandbox Code Playgroud)
最后一行不起作用,我应该使用什么呢?
当GPS进入一个确定的区域时,我的所有地理围栏都会触发,起初我认为这是因为半径,但是即使在减半之后我也遇到了同样的问题.
import UIKit
import CoreLocation
class itemDesc {
var title: String
var coordinate: CLLocationCoordinate2D
var regionRadius: CLLocationDistance
var location: String
var type: String
init(title: String, coordinate: CLLocationCoordinate2D, regionRadius: CLLocationDistance, location: String, type: String) {
self.title = title
self.coordinate = coordinate
self.regionRadius = regionRadius
self.location = location
self.type = type
}
}
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
setupData()
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: …Run Code Online (Sandbox Code Playgroud) 我目前正在 iOS 13 中测试后台位置模式,因为我想在后台跟踪用户的位置和动作(使用 CMMotionManager)。因此,我有自己的(单例)类来处理位置跟踪。我通过以下方式初始化 CLLocationManager:
func initializeLocationManager() -> CLLocationManager {
let manager = locationManager ?? CLLocationManager()
manager.delegate = self
manager.requestAlwaysAuthorization()
manager.allowsBackgroundLocationUpdates = true
manager.pausesLocationUpdatesAutomatically = false
manager.distanceFilter = kCLDistanceFilterNone
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.activityType = .other
return manager
}
Run Code Online (Sandbox Code Playgroud)
然后我启动以下服务:
func startLocationServices() {
// ...
locationManager.startUpdatingLocation()
locationManager.startMonitoringVisits()
locationManager.startMonitoringSignificantLocationChanges()
// ...
}
Run Code Online (Sandbox Code Playgroud)
此外,我还实现了 CLLocationManagerDelegate 方法 didChangeAuthorization()、didUpdateLocation()。
在 info.plist 文件中,我附加了以下条目:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>...</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>...</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
Run Code Online (Sandbox Code Playgroud)
在我的 ViewController 中,我调用了 startLocationServices。目前,我将应用跟踪位置数据的授权设置为“.authorizedAlways”
位置更新在大约 60 - 130 分钟后停止。
为了解决这个问题,我已经添加了 didFinishLaunchingWithOptions 函数,它会再次触发位置更新:
func application(_ …Run Code Online (Sandbox Code Playgroud) 对于我的应用程序,我想用iphone计算我的汽车/自行车速度.我怎样才能做到这一点?理想情况下,它应该在后台持续运行.
到目前为止,我有以下内容,但是如果没有一堆凌乱的if语句,就无法找到一个整齐的方法来获取方向字母.有任何想法吗?理想情况下,我想使用类别扩展CLLocation类来执行此操作.
-(NSString *)nicePosition{
double latitude = [self.latitude doubleValue];
double longitude = [self.longitude doubleValue];
int latSeconds = (int)round(latitude * 3600);
int latDegrees = latSeconds / 3600;
latSeconds = abs(latSeconds % 3600);
int latMinutes = latSeconds / 60;
latSeconds %= 60;
int longSeconds = (int)round(longitude * 3600);
int longDegrees = longSeconds / 3600;
longSeconds = abs(longSeconds % 3600);
int longMinutes = longSeconds / 60;
longSeconds %= 60;
//TODO: Use N,E,S,W notation in lat/long
return [NSString stringWithFormat:@"%i° %i' %i\", %i° %i' %i\"", latDegrees, …Run Code Online (Sandbox Code Playgroud) cllocation ×10
ios ×6
objective-c ×6
iphone ×3
swift ×3
background ×1
clgeocoder ×1
converter ×1
coordinates ×1
degrees ×1
geolocation ×1
performance ×1
string ×1