マップにポイントを追加しようとしています。
私はこれを得る:
- (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
しかし、それはここにあるはずです:
しかし、地図はここにそれを示しています:
場所 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
オランダにいるはずです。
誰が間違っているのか、同じ問題を抱えているのか知っていますか? 前もって感謝します
編集
米国のチュートリアルを使用し、この値を使用したためでしょうか
#define METERS_PER_MILE 1609.344