Geo Spacial Bounding Box Rectangle Calculation Error: Latitude Incorrect

后端 未结 3 863
南方客
南方客 2020-12-28 10:47

Can any trig or GPS experts help me out here? I\'m trying to create a geo-spacial bounding box (rectangle) calculation returning the maximum latitude and longitude using the

相关标签:
3条回答
  • 2020-12-28 11:33

    I haven't looked at your code, but you could also use the MapKit function MKCoordinateRegionMakeWithDistance() to have the framework calculate a bounding box for you.

    CLLocationCoordinate2D center = { 37.3, -122.0 };
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 2000.0, 2000.0);
    CLLocationCoordinate2D northWestCorner, southEastCorner;
    northWestCorner.latitude  = center.latitude  - (region.span.latitudeDelta  / 2.0);
    northWestCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);
    southEastCorner.latitude  = center.latitude  + (region.span.latitudeDelta  / 2.0);
    southEastCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
    
    0 讨论(0)
  • 2020-12-28 11:33

    How are you guys setting up the NSPredicates?

    I seem to run into performance issues with mine.

    NSPredicate *northWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat > %lf", northWestCorner.latitude];
    NSPredicate *southhWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat < %lf", southEastCorner.latitude];
    NSPredicate *latitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLat, southhWestLat, nil]];
    
    NSPredicate *northWestLng = [NSPredicate predicateWithFormat:@"ANY locations.lng < %lf", northWestCorner.longitude];
    NSPredicate *southEastLng = [NSPredicate predicateWithFormat:@"ANY locations.lng > %lf", southEastCorner.longitude];
    NSPredicate *longitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLng, southEastLng, nil]];
    
    NSPredicate *coordPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:latitudePredicate, longitudePredicate, nil]];
    
    0 讨论(0)
  • 2020-12-28 11:41

    CLLocationCoordinate2D stores coordinates in degrees, but the trig functions you're using require radian units. If you convert to radians (multiply by M_PI/180, or 0.017453293f), it will probably work.

    0 讨论(0)
提交回复
热议问题