2

Hi I'm trying to create a custom Annotation in the mapview. In mapview i have multiple pin maker in on the map when user click on the pin i want to display some text and button so have tried to create a custom Annotation view its not working.

My code

#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
      @interface myviewcon : UIViewController<MKMapViewDelegate>
      @property (strong, nonatomic) IBOutlet MKMapView *mpview;

    @end

My MKPointAnnotation code in viewdidload

for (NSDictionary *dic in [jsonArray1 valueForKey:@"houses"]) {


      MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
      NSString *name=[dic valueForKey:@"building_name"];

      CLLocationCoordinate2D placeCoord;

      placeCoord.latitude=[[dic objectForKey:@"lat"] doubleValue];
      placeCoord.longitude=[[dic objectForKey:@"lng"] doubleValue];



      [annotation setCoordinate:placeCoord];
      [annotation setTitle:name];
      [mpview addAnnotation:annotation];

      }

And my Custom Annotaionview code

  - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{

    MKAnnotationView *anview = nil;

    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    anview.rightCalloutAccessoryView=btnViewVenue;
    anview.enabled = YES;
    anview.canShowCallout = YES;
    anview.multipleTouchEnabled = NO;

    return anview;
  }

I have used the above code to make customview when user click on the pin maker on the map i have make view with text and buttons i have tired with like this but its not working i have checked with break points that delegate is calling but its not working please tell how to resolve this issue.

Thanks in Advance.

Shanthanu
  • 421
  • 1
  • 9
  • 31
  • 1
    The only problem seems to be that in viewForAnnotation, you are not creating anview. It's initialized to nil so setting properties on it does nothing. –  Mar 27 '15 at 10:13

1 Answers1

2

To customize your annotation use:

    -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 

here just add subview which you need

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    UIView *test = [[UIView alloc]initWithFrame:CGRectMake(view.frame.origin.x - 12.5, view.frame.origin.y - 45, 50, 50)];
    test.backgroundColor = [UIColor redColor];
    [_mapView addSubview:test];
}

here just delete your custom callOutView from superView

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
LoVo
  • 1,856
  • 19
  • 21
  • can please tell what is the PIN IDENTIFIER from wher i have created it – Shanthanu Mar 27 '15 at 09:02
  • That's just a string you define like a reuseIdentifier for TableCells – LoVo Mar 27 '15 at 09:10
  • You have to create the drop animation yourself now, check here:http://stackoverflow.com/questions/2139222/is-it-possible-to-call-animatesdrop-in-a-mkannotationview-rather-than-mkpinannot – LoVo Mar 27 '15 at 09:21
  • You maybe should take a look at apple documentation https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html when it is still to hard for you to make it work – LoVo Mar 27 '15 at 09:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73917/discussion-between-shantha-kumar-and-lovo). – Shanthanu Mar 27 '15 at 09:52