0

この関数を使用して、ある 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);
}

これはジオアドレスです:

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

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

@implementation GeoAddress
@synthesize distance;
@synthesize  latlng;

これはログです:

DISTANCE 15106456.105786
LOC1 -73.986357 lat 40.702645 lng
ME 40.702082 lat -73.984775 lng

数値は完全にずれています。実際の距離は ~0.17 km です。

私は何を間違っていますか??

4

3 に答える 3

5

次のような行があります。

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

明らかにそれは次のようになります。

coord.longitude = (CLLocationDegrees)[venue.lng doubleValue];
coord.latitude = (CLLocationDegrees)[venue.lat doubleValue];
于 2013-02-02T22:24:49.357 に答える
1

出力を見てください:

LOC1 -73.986357 lat 40.702645 lng
ME 40.702082 lat -73.984775 lng

あなたはMEで緯度と経度を交換しました

于 2013-02-02T22:30:30.113 に答える
1

coordから設定するvenueと、緯度と経度が逆に割り当てられます。

これで思わぬ飛距離が出ます。

于 2013-02-02T22:24:54.657 に答える