gpt4 book ai didi

iphone - 前往/缩放至当前位置功能(MapKit)

转载 作者:行者123 更新时间:2023-12-03 18:32:32 25 4
gpt4 key购买 nike

我有一个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;
}

这很好用。我添加了一个搜索栏和一个跳转到特定地址位置的功能。这也很好用。我现在想添加一个按钮来跳回当前位置。你能帮我一下吗?

干杯

最佳答案

您需要点击该按钮将 map 中心设置为当前位置。说吧,像这样:

- (IBAction)showCurrentLocation {        
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
}

关于iphone - 前往/缩放至当前位置功能(MapKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7021539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com