1

I am creating a MKMapView app where user can drag and drop annotation pin to any specific location. Until now its working. But what i want that when user click on refresh button the annotation pin should go to current user's location. So on button click what i have to make so that the pin should move from dragged location to user's location.

Thanks

iPatel
  • 46,010
  • 16
  • 115
  • 137
user1997951
  • 167
  • 1
  • 3
  • 15

2 Answers2

0

I just give you basic logic, might be helpful for you.

When your App. run first time at that time add your current lat and lon value to specific variabel. (then after do continue process for drag and drop of annotation.)

when you click on refresh button then first write

[mapView removeAnnotations:mapView.annotations];

For remove your annotation to mapView.

and then after get value of latitude and longitude from Your Variable. and write code for add annotation base on lat and long variable.

iPatel
  • 46,010
  • 16
  • 115
  • 137
  • your solution working. but the problem am getting two pins old one and new user location. am just trying to remove the old pin. as am using custom image for pin. [mapView removeAnnotations:mapView.annotations]; working but when i zoom still the dragged pin showing on map. any help here. – user1997951 Mar 28 '13 at 10:43
  • @user1997951- u have different pin color then follo this answer http://stackoverflow.com/questions/5049280/remove-mkmapview-annotations-with-a-certain-pincolor or http://stackoverflow.com/questions/13278659/remove-last-added-annotation-from-mkmapview – iPatel Mar 28 '13 at 10:48
  • `-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation; { MKAnnotationView *a = [ [ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; if ( a == nil ) a = [ [ MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier: @"currentloc" ]; a.image = [ UIImage imageNamed:@"1234.png" ]; a.draggable=YES; a.canShowCallout =YES; }`. this method calling every time when i zoom and both dragged pin and current userlocation both showing. – user1997951 Mar 28 '13 at 10:51
  • @user1997951- follo this one http://stackoverflow.com/questions/15494887/mkmapview-mkuserlocation-annotationview/15495226#15495226 – iPatel Mar 28 '13 at 10:56
0
- (void)moveToCurrentLocation:(id)sender 
{    
 [mymapview setCenterCoordinate:[mymapview.userLocation coordinate] animated:YES];
}

IT will move map view to your current location (user's location) and remove the current annotation as iPatel said in previous comment.

Apple
  • 736
  • 1
  • 6
  • 24
  • if OP manually set lat and long value then this code is not help more – iPatel Mar 28 '13 at 10:32
  • ohhk.. then sorry i can't help you more on it. but i am also eagerly waiting to see that how it is posable , and if you find it then please give me the hint as a comment on it. – Apple Mar 28 '13 at 10:35