我有MyClass
符合MKAnnotation
協議。根據documentation,類需要實現coordinate
屬性,應該返回CLLocationCoordinate2D
實例。 我的第一個執行是這樣的:在飛行創造CLLocationCoordinate2D同時符合MKAnnotation協議
-(CLLocationCoordinate2D)coordinate{
return MKCoordinateForMapPoint(MKMapPointMake(self.details.latitude, self.details.longitude));
}
但這並沒有工作:每當我叫[self.mapView addAnnotation:instanceOfMyClass];
它只是簡單地不添加到annotations
陣列mapView
的!
所以,對我來說,解決辦法是在MyClass
定義變量_coordinate
實例和實施協議一致性是這樣的:
-(CLLocationCoordinate2D)coordinate
{
_coordinate.latitude = self.details.latitude;
_coordinate.longitude = self.details.longitude;
return _coordinate;
}
現在的工作。 所以,這裏的問題是爲什麼需要有一個實例變量,並創建CLLocationCoordinate2D
即時無效?
你是對的。這也有幫助。謝謝! – peetonn 2012-08-09 13:47:28