Objective c GMMGEOTILEMAGEDATA与MapKit错误
在我的viewcontroller中,我使用贴图并加载管脚列表。 当我移动地图或放大或缩小地图时,我的应用程序崩溃并显示此错误:Objective c GMMGEOTILEMAGEDATA与MapKit错误,objective-c,ios,mkmapview,mapkit,Objective C,Ios,Mkmapview,Mapkit,在我的viewcontroller中,我使用贴图并加载管脚列表。 当我移动地图或放大或缩小地图时,我的应用程序崩溃并显示此错误: [GMMGeoTileImageData isEqualToString:]: unrecognized selector sent to instance 0x862d3b0 这是我的视图控制器代码: - (void)viewDidLoad { statoAnn = [[NSMutableString alloc] initWit
[GMMGeoTileImageData isEqualToString:]: unrecognized selector sent to instance 0x862d3b0
这是我的视图控制器代码:
- (void)viewDidLoad
{
statoAnn = [[NSMutableString alloc] initWithFormat:@"false"];
//bottone annulla per tornare indietro
UIBarButtonItem *annullaButton = [[[UIBarButtonItem alloc] initWithTitle:@"Annulla" style:UIBarButtonItemStylePlain target:self action:@selector(backView)] autorelease];
self.navigationItem.leftBarButtonItem = annullaButton;
//inizializzo la mappa
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
mapView.delegate = self;
mapView.mapType = MKMapTypeStandard;
[self.view addSubview:mapView];
[self setGmaps:arrData];
[super viewDidLoad];
}
/** inizializzo l'annotation del poi mappa **/
- (void) setGmaps:(NSMutableArray*)inputData {
// setto la lat e lng
CLLocationDegrees latitude;
CLLocationDegrees longitude;
CLLocationCoordinate2D poiLocation;
arrAnn = [[NSMutableArray alloc] init];
for(int i=0; i<[inputData count]; i++) {
//ricavo la lat e lng del pin
latitude = [[[inputData objectAtIndex:i] objectForKey:@"latitude"] doubleValue];
longitude = [[[inputData objectAtIndex:i] objectForKey:@"longitude"] doubleValue];
// setto la location del poi
poiLocation.latitude = latitude;
poiLocation.longitude = longitude;
//[[[CLLocation alloc] initWithLatitude:latitude longitude:longitude] autorelease];
//setto il pin
Annotation *ann = [[Annotation alloc] initWithCoordinate:poiLocation];
ann.title = [[inputData objectAtIndex:i] objectForKey:@"label"];
[arrAnn addObject:ann];
[ann release];
}
if (nil != self.arrAnn) {
[self.mapView addAnnotations:arrAnn];
//self.ann = nil;
self.arrAnn = nil;
}
}
/** setto il pin nella mappa ***/
- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.1f;
region.span.latitudeDelta = 0.1f;
[self.mapView setRegion:region animated:YES];
[self.mapView regionThatFits:region];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapViewTemp viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *view = nil; // return nil for the current user location
view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"];
if (nil == view) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"identifier"] autorelease];
view.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
[view setPinColor:MKPinAnnotationColorPurple];
[view setCanShowCallout:YES];
[view setAnimatesDrop:YES];
if (![statoAnn isEqualToString:@"true"]) {
CLLocation *location = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude
longitude:annotation.coordinate.longitude];
[self setCurrentLocation:location];
statoAnn = [NSMutableString stringWithFormat:@"true"];
}
return view;
}
-(void)viewDidLoad
{
statoAnn=[[NSMutableString alloc]initWithFormat:@“false”];
//每一个独立的托纳尔环
UIBarButtonItem*环形按钮=[[[UIBarButtonItem alloc]initWithTitle:@“环形”样式:UIBarButtonItemStylePlain目标:自我操作:@selector(backView)]自动释放];
self.navigationItem.leftBarButtonItem=环形按钮;
//拉马帕酒店
mapView=[[MKMapView alloc]initWithFrame:CGRectMake(0,0320416)];
mapView.delegate=self;
mapView.mapType=MKMapTypeStandard;
[self.view addSubview:mapView];
[自设置Gmap:arrData];
[超级视图下载];
}
/**地图注释**/
-(void)setgmap:(NSMutableArray*)inputData{
//拉特液化天然气公司
位置纬度;
位置经度;
CLLocationCoordination2D点定位;
arrAnn=[[NSMutableArray alloc]init];
对于注释视图中的(int i=0;i),此行:
statoAnn = [NSMutableString stringWithFormat:@"true"];
将statoAnn
设置为自动删除的字符串
当该方法退出时,release
在statoAnn
上被调用,它不再拥有它所指向的内存。当缩放或移动地图时再次调用该方法时,statoAnn
所指向的内存现在被其他东西使用(GMMGeoTileImageData
)。该对象不是NSString
,也没有isEqualToString:
方法,您将看到错误
要解决此问题,请设置statoAnn
,以便像在viewDidLoad
中一样保留该值。例如,您可以将其更改为:
statoAnn = [[NSMutableString alloc] initWithFormat:@"true"];
您还可以将statoAnn
声明为属性(@property(nonatomic,copy)NSString*statoAnn
),只需使用self.statoAnn=@“true”;
)进行设置。属性设置程序将为您执行保留操作
但是,您不需要使用字符串来保存“true”和“false”值。使用普通的BOOL
更容易、更高效,而且您不必担心保留/释放,因为它是一种基本类型而不是对象
另一件事是,viewForAnnotation
不是首先设置地图视图的区域的正确位置。添加注释后,可以在viewDidLoad
中进行设置
另一件事:在viewForAnnotation
的顶部,您有一条注释“return nil for the current user location”,但该代码没有这样做。它只是将视图初始化为nil
。要实际执行注释中的操作,您需要:
MKPinAnnotationView *view = nil;
// return nil for the current user location...
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
最后,如果dequeueReusableAnnotationViewWithIdentifier
确实返回视图(如果视图!=nil),则需要将view.annotation
设置为当前注释,因为重复使用的视图可能用于其他注释