我有一个mapView,它使用viewDidLoad缩放到当前位置:
#define METERS_PER_MILE 1609.344 // Implement viewDidLoad to do additional setup after loading the view,typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; mapView.showsUserLocation=TRUE; // zoom to a specific area CLLocationCoordinate2D zoomLocation; zoomLocation.latitude = -28.994167; zoomLocation.longitude = 134.866944; MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation,1900*METERS_PER_MILE,1900*METERS_PER_MILE); MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion]; // make sure the Google water mark is always visible mapView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); [mapView setRegion:adjustedRegion animated:YES]; mapView.delegate=self; searchBar.delegate = self; }
这很好用.我添加了一个搜索栏和一个跳转到特定地址位置的函数.这也很好.我现在想要添加一个按钮来跳回当前位置.你可以帮我一把吗?
干杯
解决方法
您需要将地图的中心设置为点按该按钮的当前位置.说,像这样:
- (IBAction)showCurrentLocation { [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。