我在地图视图中使用多个注释视图和不同的图像。图像在模拟器中正确加载但在设备中没有。我无法弄清楚这个问题的原因。以下是我的代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString * const annotationIdentifier = @"CustomAnnotation";
annotationView1 = [mapUrCommView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
MKAnnotationView *annotationView2 = nil;
if (annotationView1)
{
annotationView1.annotation = annotation;
if(mapUrCommView.userInteractionEnabled)
annotationView1.image = [UIImage imageNamed:@"MapPinDarkBlue75@2x.png"];// map-pin-black.png
else
{
//if(annotationView1.annotation == self.currentAnnotation|| annotation == self.previousAnnotation)
NSLog(@"in annotation view 1");
annotationView1.image = [UIImage imageNamed:@"mapDrawPoint@2x.png"];// Bluedot.png
}
annotationView1.tag=111;
return annotationView1;
}
else
{
annotationView2 = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
annotationView2.image = [UIImage imageNamed:@"MapPinDarkBlue75@2x.png"];// map-pin-black.png
annotationView2.canShowCallout = YES;
return annotationView2;
}
return nil;
}
这里我正在为我的应用程序中的某个位置绘制物理边界...因此注释视图1是我正在绘制的视图&amp; annoation view 2将拥有所有注释自定义视图图像(所有注释将具有相同的图像),我已经在过去绘制了..自定义注释图像在模拟器中加载正常但不在设备中
答案 0 :(得分:0)
它让我使用自定义类进行注释..请参考this示例Apple documentation。
1。)分配MapAnnotation
mapAnnotation = [[MapAnnotation alloc]init];
2。)设置纬度和长度的坐标
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([[NBCGPSLocation sharedInstance].gpsLatitude doubleValue], [[NBCGPSLocation sharedInstance].gpsLongitude doubleValue]);
[mapAnnotation setCoordinate:coord];
[self.mapSDKView addAnnotation:mapAnnotation];
3。)现在这个委托方法将在你去那个纬度和长位置时调用
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[CustomAnnotation class]])
{
if(!customAnnotationView)
customAnnotationView = [[MKAnnotationView alloc]init];
customAnnotationView.image = [UIImage imageNamed:@"locationCustom"];
customAnnotationView.annotation = annotation;
return customAnnotationView;
}
else
{
if(!annotationView)
annotationView = [[MKAnnotationView alloc]init];
annotationView.image = [UIImage imageNamed:@"locationIcon"];
annotationView.annotation = annotation;
return annotationView;
}
}