How to remove mapview annotation from another class - iphone

I have a MKMapView with lots of annotations. When I tap on an annotation, the contact details(ABPersonViewController) of the annotation is pushed. In this class I have an option to delete the contact. As the contact is deleted from the addressbook, at the same time I need to remove the annotation from the mapview too.
As the delete button is tapped, the contact is removed from the addressbook, and the ABPersonViewController class is popped from the navigation stack. Now the user sees the mapview. But it should be without the annotation(contact) which was removed.
How can I do this.

Get the annotations from the mapview using the annotation property. Then iterate through the annotation list to get the particular annotation then use the
- (void)removeAnnotation:(id < MKAnnotation >)annotation
method to remove the annotation. I hope it will take care of your problem.

Add all the annotations in a mutable array and their corresponding address with it like:
NSMutablearray *array;
[array add object:[NSDictionary dictionarywithobjectandkeys:#"your object and keys"];
Now when the user deletes the address its subsequent annotation will also be deleted. That should do it.

For deleting all annotation use the code below;
[mapView removeAnnotations:mapView.annotations]

Related

How to remove pin view?

In my app i have a MapView and one annotation. The first touch on the pin showing it's view, but i can't find the to remove/hide it on another touch.
Thanks
Removes the specified annotation object from the map view.
- (void)removeAnnotation:(id < MKAnnotation >)annotation
Parameters
annotation:
The annotation object to remove. This object must conform to the MKAnnotation protocol.
To remove annotation view only check this question
[mapView deselectAnnotation:[mapView.selectedAnnotations objectAtIndex:0] animated:YES];

Send data from chosen Annotation (InfoBoule button)

I have a mapView which loads annotations with the help of a web service. I parse the data in json in an array and get the values of each annotation.
But now, I want to send the information of the annotation in selection.
As I can think, It mar rather be like the section in UITableView called DidSelectRow...
How I can do this?
If you mean when the user taps one of the annotations in mapView, you have a delegate method for that. From MKMapViewDelegate Protocol Reference
mapView:didSelectAnnotationView:
Set your view controller as delegate for your mapView and then just use this delegate method to be notified when the user taps on one of your annotations.
Link to Apple Documentation on MKMapViewDelegate Protocol

iPhone - Updating Annotation subtitle in mapkit

I have a custom placemark with title and subtitle. The subtitle is actually displaying the address of the dropped pin using the reverse geocoder.
I have a button which has an action to drop the pin. This action gets the location coordinates of the user, and then calls [geocoder start] which gets the full address with Reverse Geocoder and generates the custom annotation and then calls [mapView addAnnotation:customPlacemark].
My problem is that using this sequence order, when there's no a WiFi connection (only 3G or maybe Edge) the pin takes a lot to drop because it's watigin to get the reverse geocoding info.
So basically I need to drop the pin without a subtitle and from the viewDidAnnotation call the geocoder and inside the reverseGeocoder update the subtitle but I'm not sure how to do that.
I want to display the annotation without the address details and update it when it gets the information from the reverse geocoder.
Any suggestions?
Thanks in advance
MKMapView observes changes its annotations via KVO. Therefore if you update your annotation's properties in a KVO compliant manner, it should Just Work.
For example, when the reverse geocoder returns an address for your annotation, you first announce the title and subtitle properties are about to change:
[self willChangeValueForKey:#"title"];
[self willChangeValueForKey:#"subtitle"];
Note that the above code is assumed to be in the annotation class.
Then update the annotation with information from the geocoder. When you are done:
[self didChangeValueForKey:#"subtitle"];
[self didChangeValueForKey:#"title"];
Note the order changed for didChangeValueForKey: as these need to be nested properly, somewhat like HTML tags.
This also works for the coordinate property, that will cause the pin to move.
I'd place the annotation, keep a reference to it in a property, then when your reverse geocoder calls back use the reference to the annotation and update its properties.

Removing multiple annotations from MapView

In my app I have two functionality when my tableview loads ,in the mapview all the pins are shown corresponding to tableData.NOw I have search bar which gives another set of values which I have to show on my mapView.Everything is working fine but second time previous pins are also shown means prevoius annotations are not deleted .
So please tell me how to remove prevoius annotation so that I can show only relavent pins on mapView
Thanks in advance
Simply use the MKMapView instance method "removeAnnotations:":
-(void)removeAnnotations:(NSArray *)annotations
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html
If you want to remove all of them you can do somethign like :
[mapView removeAnnotations:mapView.annotations];
P.S: Beware that you might want to iterate through the annotations not to remove the userLocation (blue dot)
Hope this helps,
Vincent
I got my answer my self:-
mapAddAnnotations is my arrayname and map is my mkmapview object.
[map removeAnnotations:self.mapAddAnnotations];

MapKit custom annotations being added to map, but are not visible on the map

I have an interface with a mapView and UITableView. Data is loaded from a server, and the annotations are created and added to the map with
[mapView addAnnotation:truck]
the tableview is then populated using the array thats retured from
[mapView annotations]
once this process is completed, i check the number of annotations on the map with [[mapView annotations] count] called whenever i click on a cell in the table and its equal to the number it ought to be, so all the annotations are getting added onto the mapView, but for some reason I cant see any annotations in the simulator.
The images are named just as they are assigned in the custom AnnotationView, the loadAnnotation function is done properly, etc... i dont know what it could be but ive looked at the associate between the image file and wheres its loaded a hundred times to find a discrepancy, but it all looks fine.
One interesting point is that when i print and coordinate value after clicking on the cell (remember this data comes straight from [mapView annotations], it looks good... but for whatever reason the annotation view isnt being displayed.
so i suppose if i could have the answer to one question it would be, what are possible causes for a mapView to contain several annotations, but to not show any on the map?
Thanks
EDITED WITH IMPORTANT ADDITIONAL INFO
There appears to be a disconnect between what is being displayed on my map in the simulator and what im seeing in the mapView object. For example, when i select a row in the tableView, I am calling:
[mapView setRegion:MKCoordinateRegionMake([annotation coordinate], MKCoordinateSpanMake(.01, .01)) animated:YES];
and this has no effect on the map in the simulator. I have checked that the coordinate being passed is actually a valid coordinate, but it doesnt seem to matter because the map is being unresponsive. I thought it could be something wrong with my .xib, but its all connected properly. delegate is the outlet and mapView as a referencing outlet.
Does anyone now understand what may be happening?
This really looks like missing images.
Try replacing your custom annotations with MKPinAnnotations to test, and see if your annotations are visible then.
Have you implemented the following delegate function ?
(MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation;
This line:
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
was creating messing everything up. once i commented it out, the app began working fine.