我正在尝试在地图上添加一个点。
我得到这个:
- (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