Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2012, 09:46 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default Showing details when pin tapped (MapKit)

I am trying to show the details of a location when the pin is tapped on the map view, I have added the following code:

Code:
- (void)mapView:(MKMapView *)map annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    printf("yes tapped!");
}


- (MKAnnotationView *) mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>) annotation{
    //...
}
Now viewForAnnotation does what it is supposed to do, but annotationView does not get called when a pin is tapped?


This is what's in the .h file:
Code:
@interface MapView : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate, UIAlertViewDelegate>
    //...
Anyone has any idea in why it is not working? (will post more code if required).
TelTikky is offline   Reply With Quote
Old 01-22-2012, 06:43 AM   #2 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

From the documentation of
Code:
- (void)mapView:(MKMapView *)map annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
Quote:
Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the UIControl class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.
So this method handles taps on the accessoryView of the callout not on the callout it self.

Have you set annotationView.canShowCallout = YES in
Code:
- (MKAnnotationView *) mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>) annotation
?
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-22-2012, 07:49 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default

Yeah I did, here is my complete viewForAnnotation function.

Code:
- (MKAnnotationView *) mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *aView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
    
    if(spinShouldShow == TRUE)
    {
        [mapSpinner stopAnimating];
        [mapSpinner setHidden:YES];
        spinShouldShow = FALSE;   
    }
    if(annotation.title == @"Current Location" || annotation.title == @"Specified Location")
        aView.pinColor = MKPinAnnotationColorGreen;
    if(annotation.title == @"Start Location" || annotation.title == @"End Location")
    {
        aView.pinColor = MKPinAnnotationColorPurple;
    }
    aView.animatesDrop=TRUE;
    aView.canShowCallout = YES;
    aView.calloutOffset = CGPointMake(-5, 5);
    return aView;
}
Do I have to to init AssessoryView?

Is there anyway I could just tap on the pin and then show the details of the location (possibly in subtitle or in text)? The details should only be updated when the pin is tapped.
TelTikky is offline   Reply With Quote
Old 01-22-2012, 08:57 AM   #4 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

You don't need the AccessoryView if you don't want it. For the callout View to be shown you must have set at least the title for the annotation.

Put an NSLog in your code to see if you annotation has an title.

Also MKPinAnnotationView is reusable and Apple suggest to reuse it. Also you are leaking the MKPinAnnotationView. It should be autoreleased.

You can try something like this.
Code:
static NSString *identifier = @"pin";  

 MKPinAnnotationView *aView = (MKPinAnnotationView *) [self.map dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (aView == nil) {
            aView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        } else {
            aView.annotation = annotation;
        }
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-26-2012, 08:21 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default

Thanks for the reply.

In my app the pins actually show titles and subtitles. But what I am trying to achieve is when people tap on any particular pin, it will request more info to be displayed. Which means I need to find out when a user tap a pin and which pin is tapped. Then I will use the id stored in that pin to retrieve more info from the web.
TelTikky is offline   Reply With Quote
Old 01-26-2012, 08:31 AM   #6 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Then use leftCalloutAccessoryView or rightCalloutAccessoryView to add a View to the pins Callout View. You can handle touches on the AccessoryView with

Code:
- (void)mapView:(MKMapView *)map annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-27-2012, 12:14 AM   #7 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: India
Posts: 4
KushIP is on a distinguished road
Default

Quote:
Originally Posted by TelTikky View Post
Thanks for the reply.

In my app the pins actually show titles and subtitles. But what I am trying to achieve is when people tap on any particular pin, it will request more info to be displayed. Which means I need to find out when a user tap a pin and which pin is tapped. Then I will use the id stored in that pin to retrieve more info from the web.
Use first method to get the tap on the annotation, derive your annotation class from the view object, do your operation and show the info. on the screen by un hiding a UIView with labels.

Use second method to hide that UIView again.

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

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

   
}
KushIP is offline   Reply With Quote
Old 01-27-2012, 10:46 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default

Quote:
Originally Posted by KushIP View Post
Use first method to get the tap on the annotation, derive your annotation class from the view object, do your operation and show the info. on the screen by un hiding a UIView with labels.

Use second method to hide that UIView again.

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

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

   
}
Thanks for the info. How do I get the MKAnnotation associated with the selected MKAnnotationView in didSelectAnnotationView?
TelTikky is offline   Reply With Quote
Old 01-29-2012, 07:50 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default

Quote:
Originally Posted by TelTikky View Post
Thanks for the info. How do I get the MKAnnotation associated with the selected MKAnnotationView in didSelectAnnotationView?
Ok this is what you do ...

Code:
 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
 {
 
     MapAnnotation *currentAnnotation = view.annotation;
// ...
     

 }
TelTikky is offline   Reply With Quote
Old 01-30-2012, 12:46 AM   #10 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: India
Posts: 4
KushIP is on a distinguished road
Default

Quote:
Originally Posted by TelTikky View Post
Ok this is what you do ...

Code:
 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
 {
 
     MapAnnotation *currentAnnotation = view.annotation;
// ...
     

 }
Yes, but be careful if you have multiple type of annotations...
KushIP is offline   Reply With Quote
Old 01-30-2012, 07:47 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 114
TelTikky is on a distinguished road
Default

Ok, I got the customised MKAnnotationView working, although it looked weird - instead of one view with title, subtitle and the details, I have the normal MKAnnotationView and a separate rectangle for the details.

Has anyone ever worked out how to have one view and put everything inside that view?
TelTikky is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 392
10 members and 382 guests
7twenty7, Atatator, FrankWeller, glenn_sayers, guusleijsten, iphonedevshani, MAMN84, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:46 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0