我正在构建一个在地图上跟踪用户位置的应用程序。我可以轻松插入图钉,但是当位置改变时,应用程序退出。
我在 viewdidload: 方法中将默认坐标设置为 0,0,并在该位置添加了一个图钉。我这样做是因为我想在更新位置时移除图钉,然后在新位置再次插入图钉。
这是我在 -(void)locationManager: didUpdateToLocation:fromLocation: 方法中编写的代码。
[mapview removeAnnotation:myannotation];
CLLocationCoordinate2D currentlocation;
currentlocation.latitude=newLocation.coordinate.latitude;
currentlocation.longitude=newLocation.coordinate.longitude;
myannotation=[[[CSMapAnnotation alloc]initWithCoordinate:currentlocation annotationType:CSMapAnnotationTypeStart title:@"My Location"] autorelease];
[mapview addAnnotation:myannotation];
这里,myannotation 是我要添加的引脚,newLocation 是更新的位置,CSMapAnnotation 将返回注释视图。
问题是我的应用程序每次都崩溃。在崩溃之前,我能够在控制台上收到警告消息。这是消息:
“CSMapAnnotation 类的实例 0x182020 正在被释放,而键值观察者仍向其注册。观察信息正在泄漏,甚至可能被错误地附加到其他对象。”
所以,如果有人遇到同样的问题,请帮助...