0

Hello I have a mapview that get data from plist and is shown thru map annotation. What I wanted to do is when I tapped an annotation - its details will be shown in the labels. Will anyone teach me how to do it. Here's is my plist:

<array>
     <dict>
         <key>ID</key>
         <integer>1</integer>
         <key>title</key>
         <string>Toyota Shaw</string>
         <key>address</key>
         <string>304 Shaw Blvd., Mandaluyong City</string>
         <key>tel</key>
         <string>(02) 532 8428 </string>
         <key>latitude</key>
         <real>14.589393</real>
         <key>longitude</key>
         <real>121.039589</real>
         <key>img</key>
         <string>locator_gmap_marker.png</string>
    </dict>
         ....
    <dict>
        <key>ID</key>
        <integer>10</integer>
        <key>title</key>
        <string>Toyota Gen. Santos</string>
        <key>address</key>
        <string>National Hwy., City Heights, General Santos City, South Cotabato</string>
        <key>tel</key>
        <string>(083) 554 2994</string>
        <key>latitude</key>
        <real>6.119086</real>
        <key>longitude</key>
        <real>125.159881</real>
       <key>img</key>
       <string>gmap10.png</string>
   </dict>

Thanks in advance. Here's my code in the annotation:

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

if([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

// multiple annotation
if ([annotation isKindOfClass:[AddAnnotation class]])
{
    static NSString *reuseId = @"AddAnnotation";
    mapAnnot = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];

    if (mapAnnot == nil)
        mapAnnot = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
    else
        mapAnnot.annotation = annotation;


    AddAnnotation *ann = (AddAnnotation *)annotation;

    mapAnnot.canShowCallout = YES;
    mapAnnot.image = [UIImage imageNamed:ann.image];

    return mapAnnot;
}
return nil;

} // for user location - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{

// add annotation to user location -
addAnnotation = [[AddAnnotation alloc]init];
addAnnotation.coordinate = userLocation.coordinate;
addAnnotation.title = @"I'm here";
addAnnotation.image = @"me";
[myArrayLoc addObject:addAnnotation];

[self.dealerMapLocation addAnnotations:myArrayLoc];

}

  • I have already done getting data from plist and showing it thru annotation what i wanted to do is when i tapped an annotation - its details will be shown on a label. – macky040386 Sep 30 '14 at 07:59
  • You should add a callout method when tapping the annotation and then customize which actions should be performed (updating a label, in your case). Here (http://stackoverflow.com/a/15297919/3057234) there is an explanation how to detecting interaction with MKPointAnnotation – CRoig Sep 30 '14 at 08:10
  • hello CRoig i have updated my code. Hope you can help me, still i dont have any idea how will do what i want. – macky040386 Sep 30 '14 at 09:40

1 Answers1

0

I guess that AddAnnotation class is not standard, so I would be better if you could show its declaration for checking what you changed. Anyway, I think that adding a detail button to your annotation, and then linking an action to this button will solve your problem

 UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
[button addTarget:self action:@selector(doStuffMethod) forControlEvents:UIControlEventTouchUpInside]; 
addAnnotation.rightCalloutAccessoryView = button;
CRoig
  • 691
  • 5
  • 24