草庐IT

CLLocation2DCoordinates

全部标签

ios - CLLocation distanceFromLocation : returns zero on iOS 9. 是bug吗?

重现问题的代码:-(void)testDistance{NSLog(@"Testdistance...");CLLocation*location1=[[CLLocationalloc]initWithLatitude:137.02954600000001longitude:50.543728999999999];CLLocation*location2=[[CLLocationalloc]initWithLatitude:55.79676300longitude:49.10834400];CLLocationDistancedistance=[location1distanceFro

swift - 如何将 MKUserLocation 转换为 CLLocation? - swift

我需要一种将MKUserLocation转换为CLLocation的方法,以便我可以在swift中使用distanceFromLocation方法找到用户位置与另一个预定义CLLocation之间的距离。 最佳答案 MKUserLocation有属性location,恰好是CLLocation类型。参见https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKUserLocation_Class/index.html#//apple_ref/oc

ios - 如果 Swift 中存在 NSUserDefault,则尝试更新 CLLocation

最初我试图将CLLocation保存为NSUserDefault值,然后将其作为CKRecord存储在CLoudkit中,但出现错误:“defaults.setObject(locationRecord.recordID,forKey:"locationRecordID")”原因是“尝试将非属性列表对象设置为键locationRecordID的NSUserDefaults/CFPreferences值”。所以现在我试图将纬度和经度保存为默认值并替换Cloudkit中的旧位置。我目前在“publicDB.fetchRecordWithID((defaults.objectForKey("

objective-c - CLLocation 没有显示准​​确的结果

我正在开发一个离线应用程序,我必须向用户显示行进路径,为此我正在使用MKMapview。每当我从didUpdateLocations方法获取CLLocation坐标时,它都会显示不令人满意的结果bcoz如果用户位置在路上,那么它会显示一些距离的位置,比如建筑物位置,当我绘制完整的用户行进路径时,该路径将交叉这么多建筑物,但用户在路上而不是在建筑物上旅行。那么有没有什么方法可以让我们更正这个位置坐标(不使用互联网),以便它显示准确的位置。如果没有办法做到这一点,那么任何其他出租车应用程序如何显示司机在路上的当前位置。我不想为此使用Googlemap。 最佳答案

ios - CLLocation Manager 如何在一定距离后更新

我正在使用CLLocationManagerdidupdatelocations像这样:funclocationManager(manager:CLLocationManager!,didUpdateLocationslocations:[AnyObject]!){location=locations.lastas?CLLocationNSNotificationCenter.defaultCenter().postNotificationName("location",object:self)}一切正常,但我只想在位置与原始位置相距一定距离时发布通知。我可以只使用locations.

ios - CLLocation Prompt 显示并在一瞬间消失

在我的应用程序中,我尝试从GPS获取经度和纬度。为此,我必须询问用户是否允许访问他的位置。在我这样做之前,我将这两个规则添加到Info.plist:Privacy-LocationWhenInUseUsageDescription和Privacy-LocationAlwaysUsageDescription,然后在AppDelegate中询问是否允许执行此操作(SWIFT3.0):ifCLLocationManager.locationServicesEnabled()==true{letlocalisationManager=CLLocationManager()localisati

ios - 在 Swift 中,我可以检测 CLLocation 是否有效吗?

我正在将一个位置传递给另一个UIViewController,它有一个使用prepareForSegue的MapView。我称之为receivedLocation。map以经过的位置为中心。如果用户在没有先发送位置的情况下单击按钮将他们带到map,这不会失败吗?我如何测试以查看receivedLocation是否确实包含数据,以便在map为空时将map设置为以其他内容为中心?是否会创建一个bool变量,最初将其设置为false,但在传递位置并测试时将其设置为true能否如我所愿?我看到一个名为CLLocationCoordinateIsValid的东西可用,但它的参数是一个2DCoor

swift - 尝试将 CLLocation 对象传回 iOS 应用程序扩展时,字典变为零

我正在尝试将存储的CLLocation对象从我的iOS应用程序传回扩展程序(在这种情况下:AppleWatch扩展程序)。为此,我使用推荐的openParentApplication(userInfo:[NSObject:AnyObject]!,reply:(([NSObject:AnyObject]!,NSError!)->Void)!)->Bool扩展代码中WKInterfaceController类的函数。我通过应用程序委托(delegate)的application(application:UIApplication!,handleWatchKitExtensionReques

core-data - 在 CoreData 中保存 Swift CLLocation

我试图在CoreData中保存CLLocation数据。我的属性设置为Transformable对象。那里的一些示例代码表明可以使用转换为NSValue的对象来保存位置数据。CLLocationCoordinate2DmyLocation;NSValue*locationValue=[NSValuevalueWithBytes:&myLocationobjCType:@encode(CLLocationCoordinate2D)]//thenputlocationValueintostorage-maybeanObjCcollectionclassorcoredataetc.从数据存储

swift - CLLocation distanceFromLocation(在 Swift 中?)

有人可以帮我将以下Objective-C语句转换为Swift吗?CLLocationDistancedistance=[fromLocationdistanceFromLocation:toLocation];我知道这样做一定很简单。我是iOS编程的新手,非常感谢任何帮助。谢谢!:-) 最佳答案 letdistance=fromLocation.distanceFromLocation(toLocation)新语法:letdistance=aLocation.distance(from:anotherLocation)