小编Jan*_*Jan的帖子

转到/缩放到当前位置功能(MapKit)

我有一个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;
}
Run Code Online (Sandbox Code Playgroud)

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

干杯

iphone xcode mapkit currentlocation

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

currentlocation ×1

iphone ×1

mapkit ×1

xcode ×1