简体   繁体   中英

MKMapView annotation drag and drop pin, go to user location on button click

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

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.

- (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM