iphone Detect selected MKPinAnnotation in a MapView - iphone

I have a custom MKPinAnnotation in which I have added a couple of peroperties , like the Id of the object and the type. What I want is when someone selects a pin in the MapView to detect which pin is selected and get that data.
And Show a button on its view to use that data in the button's action.
Can anyone help with this? I can't find how to detect if (and which) an annotation is selected.

There is already a built in method to take care of this situation for you. You need to use the method below. The view.annotation is the annotation that was tapped.
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"The annotation tapped is: %#", view.annotation.title);
}
Edit: It can be found here, the API is your friend.
https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/doc/uid/TP40008204

Related

MKMapKit get visible annotationviews

How can I get all the visible MKAnnotationViews in
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)clickedview
Basically I want to make some calculation to get all the views touching (in cascade) the clickedview
thanks
You can use annotationsInMapRect: to get all the annotations inside a map rect. visibleMapRect will get you the current map rect to use.

Description to current location?

Is there a way to display some text on the blue dot alike to an annotation? Right now, it only shows "current location" when the user tap on it. I want it to act somewhat like an annotation to display current address. Where there's a title and subtitle property available to use.
I thought of replacing it with my own annotation but can't figure the way to do so.
Please advise.
Thank you
You should be able to do it by implementing mapView:didSelectAnnotationView: in MKMapView Delegate...
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if(view.annotation = mapView.userLocation){
//reverse geocode mapview.userLocation.coordinate to get address
//then set title
}
}

iPhone: Question about touch events for map views

I have a mapView which has a couple of mapAnnotations. Id like to record the event when the user touches on a mapAnnoatation and then Id like to capture the information from that particular annotation and save it.
I came up with the following code to get started. But I do not see any output on my console after I build and run and the tap on an annotation on my device.
What am I doing wrong?
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
LocationMapAnnotation *tempAnnotation = view.annotation;
NSLog(#"The tapped annotation was %#", tempAnnotation.title);
}
From what I can remember, that particular method will only be called when an accessory view on an Annotation's callout view is tapped; so, for example, if you tap the blue icon in this screenshot:
By implementing the method
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
you should hopefully be able to achieve what you're after.

how to handle navigation on map annotation bubble

I trying to create an application which will show some location on map. When i click on bubble with location name, i want to navigate to different view which will some information regarding the selected location
Can anyone guide me how to do that..
Thanx
#Umang why don't to you try adding a UIButton to the MKPinAnnotationView and give it a action that will be much easier. Navigate to diffetrent view by the action of UIButton......Please have a look on this tutorial and see how the UIImageView and UIButton is added to the MKPinAnnotationView
good Luck!
You can use MKMapView delegate method
- (void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control {
// navigate to view from here
}

I don't know how to work with calloutAccessoryControlTapped:(UIControl *)control

in my project are two classes (mapViewcontroller and listViewcontroller) and on the mapView are a lot of pins that the user can pull. If he pulled one i have to save the data of the pins and manage it to the other class.
so my question what i have to implement in the following method to save the title and subtitle of the pin and use it on the other class???
enter code here- (void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annView calloutAccessoryControlTapped:(UIControl *)control {
NSLog(#"Pin gedrückt und gespeichert!", [annView description]);
}
sorry about my bad english, i hope you can help me??
greetings
Well, you can get the title and subtitle like this:
NSString *pinTitle=view.annotation.title;
NSString *pinSubtitle=view.annotation.subtitle;
To put them in a NSMutableDictionary or similar in another viewcontroller, use one of the methods recommended in the threads about sharing/accessing variables in another viewcontroller.