的MKMapView滑稽Buissness
问题描述:
我尝试在我的应用程序创建的地图部分节目,但由于某些原因注释不会将正确的MKMapView滑稽Buissness
MKMapView *mapView = (MKMapView*)self.view;
CLLocationCoordinate2D coordinate;
coordinate.latitude = 55.065767;
coordinate.longitude = -2.724609;
mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 500000, 500000);
mapView.delegate = self;
for (int i=0; i<1; i++) {
coordinate.latitude = latitude;
coordinate.longitude = longitude;
CLLocationCoordinate2D newCoord = {coordinate.latitude, coordinate.longitude};
PlaceAnnotation* annotation = [[PlaceAnnotation alloc] initWithCoordinate:newCoord];
//annotation.mTitle = companyTitle;
//annotation.mSubtitle = companyDescription;
[mapView addAnnotation:annotation];
[annotation release];
}
}
,并在我的地方annotaion
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate{
self = [super init];
if (self != nil) {
_coordinate = coordinate;
}
return self;
}
lattitude和longditude都有正确的值,我以前使用过这个代码,但使用指向一个对象的数组,它工作正常,但是当我尝试直接给它的值时,它会失败
谁能帮我出
*编辑,对不起,我已经有我Viewforannotation刚刚在副本中错过了
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != mV.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mV dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinAnnotation == nil)
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinAnnotation.canShowCallout = YES;
//instatiate a detail-disclosure button and set it to appear on right side of annotation
}
return pinAnnotation;
[pinAnnotation release];
}
答
您的PlaceAnnotation需要实现MKAnnotation协议。具体而言,该方法
- (CLLocationCoordinate)coordinate;
,或者你可以定义属性,并将其设置在构造函数
@property (assign) CLLocationCoordinate coordinate
这是怎样的MKMapView知道在何处放置注解。
p.s. 此外,我不知道如何犹太是这样的:
CLLocationCoordinate2D newCoord = {coordinate.latitude, coordinate.longitude};
这也许很好,但苹果公司推荐:
CLLocationCoordinate2D newCoord = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
答
您需要实现MKMapViewDelegate协议方法
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
供应一个MKAnnotationView实例(或子类)用来显示注释。详情请参阅MKMapViewDelegate protocol reference。