iphone – 转到/缩放到当前位置功能(MapKit)
发布时间:2020-12-14 20:01:04 所属栏目:百科 来源:网络整理
导读:我有一个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.showsUserLocati
我有一个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]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |