简体   繁体   English

MKMapView注释拖放图钉,单击按钮转到用户位置

[英]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. 我正在创建一个MKMapView应用程序,用户可以在其中将注释图钉拖放到任何特定位置。 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. 因此,在按钮上单击我必须做的,以便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 . 第一次运行时,将您当前的经纬度值添加到特定的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. 用于将注释删除到mapView。

and then after get value of latitude and longitude from Your Variable . 然后得到后的价值latitudelongitude从您的变量 and write code for add annotation base on lat and long variable. 并根据lat和long变量编写代码以添加注释。

- (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. IT会将地图视图移动到您的当前位置(用户的位置),并删除当前注释,如iPatel在先前评论中所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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