标签: cllocation

用于计算轴承w/Haversine功能的CLL位类别

我正在尝试为CLLocation编写一个类别,以将轴承返回到另一个CLLocation.

我相信我对公式做错了(计算不是我的强项).返回的轴承始终关闭.

我一直在看这个问题并尝试应用被接受为正确答案的更改及其引用的网页:

计算两个CLLocationCoordinate2D之间的方位

http://www.movable-type.co.uk/scripts/latlong.html

谢谢你的任何指示.我已经尝试将其他问题的反馈结合起来,而我仍然没有得到任何东西.

谢谢

这是我的类别 -

----- CLLocation + Bearing.h

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>


@interface CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation;
-(NSString *) compassOrdinalToLocation:(CLLocation *) nwEndPoint;

@end
Run Code Online (Sandbox Code Playgroud)

--------- CLLocation + Bearing.m

#import "CLLocation+Bearing.h"

double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};


@implementation CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation {

 double lat1 = DegreesToRadians(self.coordinate.latitude);
 double lon1 = DegreesToRadians(self.coordinate.longitude);

 double lat2 = DegreesToRadians(destinationLocation.coordinate.latitude);
 double lon2 = DegreesToRadians(destinationLocation.coordinate.longitude);

 double dLon = lon2 …
Run Code Online (Sandbox Code Playgroud)

iphone core-location mapkit haversine cllocation

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

CLLocationManager和准确性问题 - 任何经验?

所以我正在处理iPhone GPS的一些准确性问题.我有一个使用位置的应用程序.

在委托方法中,locationManager: didUpdateToLocation: fromLocation:我正在返回一个位置.从一些研究来看,似乎GPS在返回的第一个结果上并不总是准确的,即使设置desiredAccuracy属性也是如此kCLLocationAccuracyBest.

为了解决这个问题,我不会stopUpdatingLocation在它返回newLocation:至少3次之前打电话(这很快).我还玩过两个关于是否stopUpdatingLocation返回的"要求" newLocation.我尝试的一种方法是检查lat和long newLocation并进行比较oldLocation,如果这些不相同,则保持位置更新运行.我也试图与检查之间的距离oldLocationnewLocation,如果它小于20米,它的罚款.这两个都是通过返回至少3次运行来测试的.后一种方式不那么"严格",因为如果用户在移动的车辆中,newLocation并且oldLocation很难与100%完全相同.

现在,我的问题是,即使在进行上述操作时(基本上不接受某个位置,直到发生一些更新并CLLocationManager检查CLLocations它们之间的距离(或者它们是否相同),我仍然看到有时奇怪的位置结果,在测试时.

如果我离开应用程序,进入Maps.app,使用GPS,然后打开多任务处理,强制退出我的应用程序,然后重新打开它以获得干净的启动,有时会修复.

人们习惯于解决同类问题的经验和可能的解决方案?评论和解决方案赞赏:)

cllocationmanager cllocation ios

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

如何在ios中多次停止调用didUpdateLocations()的方法

这是我的代码......

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
 {

    location_updated = [locations lastObject];
    NSLog(@"updated coordinate are %@",location_updated);
    latitude1 = location_updated.coordinate.latitude;
    longitude1 = location_updated.coordinate.longitude;

    self.lblLat.text = [NSString stringWithFormat:@"%f",latitude1];
    self.lblLon.text = [NSString stringWithFormat:@"%f",longitude1];

    NSString *str = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude1,longitude1];
    url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    connection = [NSURLConnection connectionWithRequest:request delegate:self];
    if (connection)
    {
        webData1 = [[NSMutableData alloc]init];
    }
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(latitude1,longitude1);
        marker.title = formattedAddress;
        marker.icon = [UIImage imageNamed:@"m2.png"];
        marker.map = mapView_;
        marker.draggable = YES;
 }
Run Code Online (Sandbox Code Playgroud)

这个方法多次调用,我不想......

iphone cllocationmanager cllocation ios

27
推荐指数
4
解决办法
2万
查看次数

计算Swift中两个CLLocation点之间的方位

我正在尝试计算仅限swift的代码中两个CLLocation点之间的方位.我遇到了一些困难,并假设这是一个非常简单的功能.堆栈溢出似乎没有列出任何内容.

func d2r(degrees : Double) -> Double {
    return degrees * M_PI / 180.0
}

func RadiansToDegrees(radians : Double) -> Double {
    return radians * 180.0 / M_PI
}


func getBearing(fromLoc : CLLocation, toLoc : CLLocation) {

    let fLat = d2r(fromLoc.coordinate.latitude)
    let fLng = d2r(fromLoc.coordinate.longitude)
    let tLat = d2r(toLoc.coordinate.latitude)
    let tLng = d2r(toLoc.coordinate.longitude)

    var a = CGFloat(sin(fLng-tLng)*cos(tLat));
    var b = CGFloat(cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(fLng-tLng))

    return atan2(a,b)
}
Run Code Online (Sandbox Code Playgroud)

我的atan2调用关于lvalue cgfloat或其他东西我收到错误...

cllocation ios swift

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

Swift - CLGeocoder reverseGeocodeLocation completionHandler闭包

我正在试图做的是传递CLLocation给函数getPlacemarkFromLocation,然后使用传递CLLocation通过reverseGeocodeLocation设置CLPlacemark?将返回.

我在创建completionHandler闭包时遇到问题reverseGeocodeLocation,它会抛出编译器错误/崩溃:


在斯威夫特,CLGeocodeCompletionHandlerCLGeocodeCompletionHandler = (AnyObject[]!, NSError!) -> Void根据文档AnyObject[]!应该包含CLPlacemark的对象,就像Objective-C的版本.

这是我目前的代码:

class func getPlacemarkFromLocation(location:CLLocation)->CLPlacemark?{
    var g = CLGeocoder()
    var p:CLPlacemark?
    g.reverseGeocodeLocation(location, completionHandler: {
        (placemarks, error) in
        let pm = placemarks as? CLPlacemark[]
        if (pm && pm?.count > 0){
            p = placemarks[0] as? CLPlacemark
        }
    })
    return p?
}
Run Code Online (Sandbox Code Playgroud)

编辑:似乎错误placemarks.countplacemarks没有像数组一样对待.它现在编译,但是当我试图进入p内部时,我只得到零completionHandler.我检查了CLLocation被传递的内容并且它们是有效的. …

mapkit mkmapview cllocation ios swift

22
推荐指数
2
解决办法
3万
查看次数

字符串到CLLocation纬度和经度

我有两个代表纬度和经度的字符串,如:" - 56.6462520",我想分配给一个CLLocation对象来比较我当前的位置.我尝试了下面的代码,但我只得到错误:

CLLocation * LocationAtual = [[CLLocation alloc]init];
LocationAtual.coordinate.latitude = @"-56.6462520";
LocationAtual.coordinate.longitude = @"-36.6462520";
Run Code Online (Sandbox Code Playgroud)

然后将对象与我的实际位置纬度和经度进行比较.有什么建议?

string iphone objective-c cllocation

20
推荐指数
3
解决办法
5万
查看次数

使用纬度和经度在swift中初始化CLLocation对象

在目标C(我没有经验)你可以用纬度和经度初始化一个CLLocation对象,如下所示:

CLLocation *myLocation = [[CLLocation alloc]  initWithLatitude:your_latitiude_value longitude:your_longitude_value];
Run Code Online (Sandbox Code Playgroud)

但是我如何在Swift中做到这一点?

我试过这个,

let loc_coords = CLLocationCoordinate2D(latitude: your_latitiude_value, longitude: your_longitude_value)

let loc = CLLocation().coordinate(loc_coords)
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

无法使用类型'(CLLocationCoordiate2D)'的参数列表调用"coordinate"

我需要它作为CLLocation对象,因为我想在locationManager中使用distanceFromLocation方法.

希望你能帮忙,谢谢!

latitude-longitude cllocation cllocationdistance cllocationcoordinate2d swift

20
推荐指数
2
解决办法
3万
查看次数

如何在不使用MKMapView的情况下检查MKCoordinateRegion是否包含CLLocationCoordinate2D?

我需要检查用户位置是否属于MKCoordinateRegion.我很惊讶没有为此找到简单的功能,例如:CGRectContainsCGPoint(rect,point).

我找到了以下代码:

CLLocationCoordinate2D topLeftCoordinate = 
    CLLocationCoordinate2DMake(region.center.latitude 
                               + (region.span.latitudeDelta/2.0), 
                               region.center.longitude 
                               - (region.span.longitudeDelta/2.0));


    CLLocationCoordinate2D bottomRightCoordinate = 
    CLLocationCoordinate2DMake(region.center.latitude 
                               - (region.span.latitudeDelta/2.0), 
                               region.center.longitude 
                               + (region.span.longitudeDelta/2.0));

        if (location.latitude < topLeftCoordinate.latitude || location.latitude > bottomRightCoordinate.latitude || location.longitude < bottomRightCoordinate.longitude || location.longitude > bottomRightCoordinate.longitude) {

    // Coordinate fits into the region

    }
Run Code Online (Sandbox Code Playgroud)

但是,我不确定它是否准确,因为文档没有准确指定区域矩形的计算方式.

必须有更简单的方法来做到这一点.我是否忽略了MapKit框架文档中的某些功能?

iphone mkcoordinateregion cllocationmanager cllocation ios

19
推荐指数
5
解决办法
2万
查看次数

如何测量两个CLLocations之间的距离(米)?

我怎样才能得到两米之间的距离CLLocationCLLocation它没有提供任何方法来实现它.

cocoa-touch objective-c core-location cllocation

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

把CLLocationCoordinate2D放到Swift的CLLocation中

我有一个我想要调用的方法但是当我回到地图的中心时,它处于CLLocationCoordinate2D类型.

如何将CLLocationCoordinate2D的结果放入CLLocation?

mapkit cllocation ios cllocationcoordinate2d swift

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