标签: cllocation

将Cocoa Touch纬度/经度转换为不带度数符号的字符串

我正在尝试将CLLocation纬度/经度转换为字符串.我可以使用以下代码成功完成此操作:

// extract latitude from CLLocation object and cast to string
NSString *latitude = [[NSString alloc] initWithFormat:@"%g°", location.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)

这给了我一个像34.10111º的值.我希望这个数字是一个没有º度符号的纯字符串.

我应该用不同的格式初始化字符串吗?

我尝试使用格式@"%d"启动,字符串完全出现在另一个数字上.

cocoa cocoa-touch latitude-longitude nsstring cllocation

1
推荐指数
1
解决办法
1万
查看次数

如何计算地理点周围的矩形?

每当位置发生变化时,CLLocationManager都会向我的委托发送新的CLLocation.该位置的坐标表示为CLLocationCoordinate2D对象,该对象仅包含纬度和经度.我想取这个位置,确定南纬1000米,西经1000度,北纬1000米,东经1000米的纬度和经度.这样我最终得到位于该位置西南方向的一个坐标和该位置的一个东北方向.

我不知道如何做到这一点,今晚我的GoogleFoo看起来很糟糕.我发现的哪些信息提供了难以理解的数学.有人帮助brotha黑客吗?如果有的话,我可以使用iOS API,但是只对doublelat和long的值进行操作的等式会更好.它不必在厘米内准确,但在米内会很好.理想情况下,它看起来像这样:

NSArray *rect = CalculateRectangleFromLocation(
    clLocationCoordinate2D,
    1000.0
);
Run Code Online (Sandbox Code Playgroud)

然后*rect将有四个值:西南角的纬度和长度以及东北角的纬度和长度.

geolocation latitude-longitude cllocation

1
推荐指数
1
解决办法
2867
查看次数

CLLocationManager提示符正在显示警报然后消失

这是一个可怕的错误.使用CLLocationManger时,无论是使用startUpdatingLocation还是使用ALAsset方法来访问照片的元数据,系统都会按预期提示进行位置访问...但是一旦显示,提示就会消失.我找不到这个的原因,我希望别人有这个问题.其他警报(例如显示UIAlertView)不会发生这种情况.

我甚至可以设置目的属性,然后显示,但只是暂时,它只是关闭自己.

这对我来说是个大问题,因为我需要获得许可才能使用照片元数据.

iphone cllocationmanager cllocation alassetslibrary ios5

1
推荐指数
1
解决办法
957
查看次数

在Swift中将CLLocationSpeed转换为long

我正试图在Swift中获得GPS速度.我已经把一切都搞定了,现在我正在尝试做一些计算.我想将MS"字符串"转换为KMH.所以我试图将类型转换为long,但我无法让它工作.

我试过这个:

var ms: long?
ms = LocationManager.location.speed
Run Code Online (Sandbox Code Playgroud)

但我得到"CLLocationspeed不能长期转换"

我是iOS编程和Swift的新手,所以我不知道如何解决这个问题.

cllocation ios swift

1
推荐指数
1
解决办法
2821
查看次数

从 Core Data 创建一个 CLLocation 坐标数组

也许我找不到这个问题的答案,因为它非常简单,我应该能够弄清楚,但我很难过。哦,如果我的一些术语被关闭,我很抱歉 - 我还在学习。

我正在使用 Swift 并且有一个从 Core Data 派生的数组。到现在为止还挺好。此数组中的两个元素是存储纬度和经度的 Doubles/NSNumbers。我将使用这两个元素在地图上绘制,但我不知道如何将这两个元素放入它们自己的 CLLocations 数组中。

所以,我在 Core Data 中得到了所有数据的数组:

var locationsList: [Locations] = []

 var context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
    var request = NSFetchRequest(entityName: "Locations")
    let pred = NSPredicate(format: "game = %d", passedGameNumber)
    request.predicate = pred
    request.sortDescriptors = [NSSortDescriptor(key:"time", ascending: false)]
    self.locationsList = context.executeFetchRequest(requestMap, error: nil)! as [Locations]
Run Code Online (Sandbox Code Playgroud)

但它保存了 Core Data 中所有内容的数据(按游戏过滤):

class Locations: NSManagedObject {

@NSManaged var game: NSNumber
@NSManaged var time: NSDate
@NSManaged var latitude: NSNumber
@NSManaged var longitude: NSNumber

} …
Run Code Online (Sandbox Code Playgroud)

arrays core-data cllocation swift

1
推荐指数
1
解决办法
4799
查看次数

didUpdateLocation未在首次运行时调用

我的应用中的定位服务在您首次运行时无法正常工作。第二次以及之后的任何时间,它都可以正常工作。这是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.allowsBackgroundLocationUpdates = true;
[locationManager requestAlwaysAuthorization];

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways ||
    [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
    [locationManager startUpdatingLocation];
}
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
latitude = locationManager.location.coordinate.latitude;
longitude = locationManager.location.coordinate.longitude;
NSLog(@"New Location. Lat: %f, Long: %f", latitude, longitude);
}
Run Code Online (Sandbox Code Playgroud)

iphone cllocation ios

1
推荐指数
1
解决办法
610
查看次数

将CLLocationCoordinate2D的字符串转换为数组

更新先前的问题以获得更好的解释。

var breadcrumbs: [CLLocationCoordinate2D] = []
var path: [CLLocationCoordinate2D] = []
Run Code Online (Sandbox Code Playgroud)

每10秒钟调用一次,以将CLLocationCoordinate2D附加到数组。

func addBreadcrumb(){
    let speed = (locationmanager.location?.speed)!
    let speedRounded = speed.roundTo(places: 4)
    let crumbCoordinate = locationmanager.location?.coordinate

    breadcrumbs.append(crumbCoordinate!)
    tripSpeeds.append(speedRounded)
}
Run Code Online (Sandbox Code Playgroud)

一旦用户完成行程,他们便会点击一个按钮,并调用以下功能。这会将数据输入到Firebase中。我将另存为字符串,否则将收到错误消息。

func submitTripPath(){
    let tripID: String? = tripUID
    let tripPath = String(describing: breadcrumbs) //This may be the problem
    let speeds = String(describing: tripSpeeds)

    var ref: FIRDatabaseReference!
    ref = FIRDatabase.database().reference()
    let tripRef = ref.child("TripPaths").child(tripID!)
    let tripDictionary = ["routePath" : tripPath, "routeSpeed" : speeds] as [String : Any]
    tripRef.updateChildValues(tripDictionary) { (err, ref) …
Run Code Online (Sandbox Code Playgroud)

cllocation ios firebase swift firebase-realtime-database

1
推荐指数
1
解决办法
514
查看次数

如何从坐标中获取地址

我想从坐标中获取地址。我在下面附上了我的代码..

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let lastLocation = locations.last!
    let latvalue     = lastLocation.coordinate.latitude
    let lngvalue     = lastLocation.coordinate.longitude
    self.db_latvalue = latvalue
    self.db_lngvalue = lngvalue
    let location = CLLocation(latitude: latvalue, longitude:lngvalue)
    let address = CLGeocoder.init()
    address.reverseGeocodeLocation(CLLocation.init(latitude: latvalue, longitude:lngvalue)) { (places, error) in
        if error == nil{
            if let place = places{
                   print("addressshowingssq \(place)")
                self.db_address = "\(place)"

            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

输出:

[L-30 2nd A Main Road, L-30 2nd A Main Road, HSR Layout, Bengaluru, Karnataka 560102, India @ <+12.91597974,+77.62879254> …

cllocation ios cllocationcoordinate2d swift

1
推荐指数
1
解决办法
1521
查看次数

如何使用 SwiftUI 中的扩展将 Hashable 协议添加到 CLLocationCoordinate2D

所以我有一个自定义结构,其中一个属性为 String 类型,另一个为 CLLocationCoordinate2D 类型。显然,String 符合 Hashable,如果我可以扩展 CLLocationCoordinate2D 以符合 Hashable,我的自定义结构也将是 Hashable。这是我扩展 CLLocationCoordinate2D 的尝试:

extension CLLocationCoordinate2D {
    static func == (lhs: Self, rhs: Self) -> Bool {
        return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
    }
    
    func hash(into hasher: inout Hasher) {
        hasher.combine(self.latitude) //wasn't entirely sure what to put for the combine parameter but I saw similar things online
    }
}
Run Code Online (Sandbox Code Playgroud)

cllocation hashable swift swiftui

1
推荐指数
1
解决办法
169
查看次数

CLLocationDistance返回完全错误的值

我正在使用此函数来获取从一个CLLocation到另一个CLLocation的距离

这里的venue.lat是NSNumber

GeoAddress *address = [[GeoAddress new] init];

CLLocationCoordinate2D coord;
coord.longitude = (CLLocationDegrees)[venue.lat doubleValue];
coord.latitude = (CLLocationDegrees)[venue.lng doubleValue];

address.latlng = [[CLLocation alloc] initWithLatitude:coord.latitude longitude: coord.longitude];

if (curUserLocation.coordinate.latitude){
    address.distance = [address.latlng distanceFromLocation:curUserLocation];
    NSLog(@" DISTANCE %f", address.distance);
    NSLog(@" LOC1 %f lat %f lng", address.latlng.coordinate.latitude, address.latlng.coordinate.longitude);
    NSLog(@" ME %f lat %f lng", curUserLocation.coordinate.latitude, curUserLocation.coordinate.longitude);
}
Run Code Online (Sandbox Code Playgroud)

这是Geoaddress:

//  GeoAddress.h
@interface GeoAddress : NSObject
{        
    CLLocation * latlng;
   CLLocationDistance  distance;
}
@property  CLLocationDistance  distance;
@property (nonatomic, retain)  CLLocation * latlng;

//  GeoAddress.m
#import "GeoAddress.h"

@implementation …
Run Code Online (Sandbox Code Playgroud)

objective-c cllocation ios cllocationdistance

0
推荐指数
1
解决办法
1793
查看次数