how to handle navigation on map annotation bubble - iphone

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
}

Related

iphone Detect selected MKPinAnnotation in a MapView

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

Mapview refresh not working

I'm showing the route between 2 places. My project is a navigation based project. In the viewWillAppear: method I track the current location of the user using location manager. In the
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation method I get the coordinates of the user's current location.
I draw the map with this. Now when I get back to the previous view and come back map view it doesn't load the user location. It doesnt call - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation method.
How can I rectify this? I need to get the map route everytime I come to this class.
Thanks in advance
I am about to answer my own question with this as well:
I saw posts on how to reset the view, redraw the layer etc. I am fairly (not new) inexperienced with the language, so what I have done is a hack, but it works. I hope you use this if you have to, but find a better solution.
View Controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],2587600.0, 2587600.0);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],5.0, 5.0);
}
So when the view leaves, well... view, then the map zooms really far in. When the view returns to view, the the data is reloaded and voila. Your mileage may vary, but this method works perfectly for what I need it to do.
And it is not a jarring effect at all. It is seamless. From a UI standpoint, nothing changes.
cheers!
Robert

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.

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.