经度纬度点的奇怪位置

时间:2012-11-14 10:03:25

标签: ios mapkit latitude-longitude point

我正在尝试向地图添加一个点。

我得到了这个:

- (void)plotCrimePositions:(NSData *)responseData {
    for (id<MKAnnotation> annotation in _mapView.annotations) {
        [_mapView removeAnnotation:annotation];
    }

    NSDictionary *root = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
    NSArray *data = [root objectForKey:@"features"];
    NSLog(@"features: %@", data );

    for (NSDictionary *dic in data) {
        NSDictionary *geometry = [dic objectForKey:@"geometry"];
        // Do what you want..
        NSNumber *latitude = [geometry objectForKey:@"x"];
        NSNumber *longitude = [geometry objectForKey:@"y"];
        NSString *crimeDescription = @"test";
        NSString *address = @"banaan";

        NSLog(@"latitude: %@", latitude );
        NSLog(@"longitude: %@", longitude );
        NSLog(@"error: %@", crimeDescription );
        NSLog(@"error: %@", address );

        CLLocationCoordinate2D coordinate;
        coordinate.latitude = latitude.doubleValue;
        coordinate.longitude = longitude.doubleValue;
        NSLog(@"latitude2: %f", coordinate.latitude );
        NSLog(@"longitude2: %f", coordinate.longitude );


        MyLocation *annotation = [[MyLocation alloc] initWithName:crimeDescription address:address coordinate:coordinate] ;
        [_mapView addAnnotation:annotation];
    }
}

我认为这是NSLog:

2012-11-14 10:57:02.404 ArrestPlotter[9254:907] Response: {"displayFieldName":"Gecontroleerd","fieldAliases":{"Gecontroleerd":"Gecontroleerd"},"geometryType":"esriGeometryPoint","spatialReference":{"wkid":4326},"fields":[{"name":"Gecontroleerd","type":"esriFieldTypeString","alias":"Gecontroleerd","length":255}],"features":[{"attributes":{"Gecontroleerd":"Ja"},"geometry":{"x":5.9680979652859065,"y":52.507071127790766}}]}
2012-11-14 10:57:02.421 ArrestPlotter[9254:907] features: (
        {
        attributes =         {
            Gecontroleerd = Ja;
        };
        geometry =         {
            x = "5.968097965285907";
            y = "52.50707112779077";
        };
    }
)
2012-11-14 10:57:02.423 ArrestPlotter[9254:907] latitude: 5.968097965285907
2012-11-14 10:57:02.424 ArrestPlotter[9254:907] longitude: 52.50707112779077
2012-11-14 10:57:02.425 ArrestPlotter[9254:907] error: test
2012-11-14 10:57:02.426 ArrestPlotter[9254:907] error: banaan
2012-11-14 10:57:02.427 ArrestPlotter[9254:907] latitude2: 5.968098
2012-11-14 10:57:02.437 ArrestPlotter[9254:907] longitude2: 52.507071

但它应该在这里: Holland

但是地图在这里显示: Africa somewhere

它说的位置  2012-11-14 10:57:02.427 ArrestPlotter [9254:907] latitude2:5.968098     2012-11-14 10:57:02.437 ArrestPlotter [9254:907]经度2:52.507071

应该在荷兰。

有谁知道我做错了什么或有同样的问题? 提前致谢

修改

可能是因为我使用了美国的教程而且我使用了这个值

#define METERS_PER_MILE 1609.344

2 个答案:

答案 0 :(得分:2)

尝试搜索Google地图。那就是那些坐标。

您正在反向输入它们。如果你颠倒这两个数字,那么你就在荷兰。

答案 1 :(得分:2)

您正在以错误的方式设置经度和纬度:

NSNumber *latitude = [geometry objectForKey:@"x"];
NSNumber *longitude = [geometry objectForKey:@"y"];

应该是:

NSNumber *latitude = [geometry objectForKey:@"y"];
NSNumber *longitude = [geometry objectForKey:@"x"];