Ios5 ios地图批注出现在错误的位置
我正在用IOS SDK 5.1和MapKit开发一个应用程序。我有以下代码在从api检索数据后在地图上放置注释Ios5 ios地图批注出现在错误的位置,ios5,mapkit,mkannotation,Ios5,Mapkit,Mkannotation,我正在用IOS SDK 5.1和MapKit开发一个应用程序。我有以下代码在从api检索数据后在地图上放置注释 - (void)placeAnnotationsOnMap:(NSString *)responseString { for (id<MKAnnotation> annotation in _mapView.annotations) { [_mapView removeAnnotation:annotation]; } NSData *jsonData = [re
- (void)placeAnnotationsOnMap:(NSString *)responseString {
for (id<MKAnnotation> annotation in _mapView.annotations) {
[_mapView removeAnnotation:annotation];
}
NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *e = nil;
NSArray *jsonArray =
[NSJSONSerialization
JSONObjectWithData: jsonData
options: kNilOptions
error: &e];
for(NSArray *cache in jsonArray ){
for(NSDictionary *item in jsonArray) {
NSLog(@"Item: %@", item);
NSString * comment = [item objectForKey:@"comment"];
NSNumber * latitude = [item objectForKey:@"locationLat"];
NSNumber * longitude = [item objectForKey:@"locationLong"];
NSString * numCachers = [item objectForKey:@"numCachers"];
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
CustomAnnotation *cacheAnnotation = [[CustomAnnotation alloc] initWithTitle:comment numCachers:numCachers coordinate:coordinate];
[_mapView addAnnotation:cacheAnnotation];
}
}
-(void)placeAnnotationsOnMap:(NSString*)responseString{
对于(在_mapView.annotations中的id注释){
[_MapViewRemoveAnnotation:annotation];
}
NSData*jsonData=[responseString数据使用编码:NSUTF8StringEncoding];
n错误*e=零;
NSArray*jsonArray=
[NSJ串行化
JSONObjectWithData:jsonData
选项:针织品
错误:&e];
用于(NSArray*jsonArray中的缓存){
for(jsonArray中的NSDictionary*项){
NSLog(@“项:%@”,项);
NSString*comment=[ItemObjectForkey:@“comment”];
NSNumber*纬度=[item objectForKey:@“locationLat”];
NSNumber*经度=[item objectForKey:@“locationLong”];
NSString*numCachers=[ItemObjectForkey:@“numCachers]”;
CLLocationCoordinate2D坐标;
坐标.纬度=纬度.双值;
coordinate.longitude=longitude.doubleValue;
CustomAnnotation*cacheAnnotation=[[CustomAnnotation alloc]initWithTitle:comment numCachers:numCachers坐标:坐标];
[_MapViewAddAnnotation:cacheAnnotation];
}
}
}
以及我对注释方法的看法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"CustomAnnotation";
CLLocationCoordinate2D coord = [annotation coordinate];
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
return annotationView;
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
静态NSString*标识符=@“CustomAnnotation”;
CLLocationCoordinate2D坐标=[注释坐标];
MKPinAnnotationView*annotationView=(MKPinAnnotationView*)[\u地图视图排队可重用AnnotationViewWithIdentifier:identifier];
如果(注释视图==nil){
annotationView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:标识符];
}否则{
annotationView.annotation=注释;
}
annotationView.enabled=是;
annotationView.canShowCallout=是;
返回注释视图;
}
问题是注释出现在错误的位置。目前,我从后端服务返回一个位置,该位置具有华盛顿特区白宫的经纬度。问题是这种注释在中国出现了
即使我将lat长硬编码为38.8977、77.0366(基本上不是从json响应解析),它也会出现在中国
关于我做错了什么有什么想法吗?有趣的是,似乎所有其他地方都很好。也许在白宫丢别针有一些安全限制
更新…安娜在下面是正确的!:) 有趣的是,似乎所有其他位置都可以正常工作。也许在白宫丢别针有一些安全限制
更新…安娜在下面是正确的!:) 在MapKit中坐标的表示是错误的,但我确信它们在CLLocation坐标中是正确的在MapKit中坐标的表示是错误的,但我确信它们在CLLocation坐标中是正确的没有这样的限制。白宫在38.8977,-77.0366(负77度,即西而非东)。真不敢相信我错过了。谢谢没有这样的限制。白宫在38.8977,-77.0366(负77度,即西而非东)。真不敢相信我错过了。谢谢这是评论,不是回答这是评论,不是回答