Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to make a map, where I can see my current location, and see what the street is called.

so far, I am able to put a pin on my map, but for some reason, I am not getting the callout. and I have put a NSLog in my viewForAnnotation method, but it is not being called, so i wasn't able to test it.

can someone help me?

-(void)lat:(float)lat lon:(float)lon
{
    CLLocationCoordinate2D location;
    location.latitude = lat;
    location.longitude = lon;
    NSLog(@"Latitude: %f, Longitude: %f",location.latitude, location.longitude);
    //One location is obtained.. just zoom to that location

    MKCoordinateRegion region;
    region.center=location;
    //Set Zoom level using Span
    MKCoordinateSpan span;
    span.latitudeDelta=.005f;
    span.longitudeDelta=.005f;
    region.span=span;
    [map setRegion:region animated:TRUE];

    //MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:location];
    //geocoder.delegate=self;
    //[geocoder start];
    if (cPlacemark != nil) {
        [map removeAnnotation:cPlacemark];
    }
    cPlacemark=[[CustomPlacemark alloc] initWithCoordinate:location];
    cPlacemark.title = mPlacemark.thoroughfare;
    cPlacemark.subtitle = mPlacemark.locality;
    [map addAnnotation:cPlacemark];
    [cPlacemark release];

    [mLocationManager stopUpdatingLocation];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

// try to dequeue an existing pin view first
if ([annotation isKindOfClass:[CustomPlacemark class]]){
MKPinAnnotationView *pinView=(MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:@"customIdentifier"];

if (!pinView)
{
    // if an existing pin view was not available, create one
    MKPinAnnotationView* cPinAnnoView = [[[MKPinAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:@"customIdentifier"] autorelease];
    cPinAnnoView.pinColor = MKPinAnnotationColorPurple;
    cPinAnnoView.animatesDrop = YES;
    cPinAnnoView.canShowCallout = YES;
    // Add button
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [leftButton addTarget:self action:@selector(annotationViewClick:) forControlEvents:UIControlEventTouchUpInside];
    cPinAnnoView.leftCalloutAccessoryView = leftButton;

} else
    {
        pinView.annotation = annotation;
    }
    return pinView; 
}
return nil;

}

Right now I have customized my viewForAnnotation to be like this. But I still can't get a callout from my pin and the pin remains red. But it should be purple of nothing at all

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
728 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had the same problem which was not setting the MapView delegate to the File Owner.

  1. Open your nib
  2. Right click on the MapView
  3. Drag the delegate to the File's Owner

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...