ios - 如何放大和居中用户位置(Objective-C)

标签 ios objective-c mapkit

如何放大并将用户位置“点”居中?我已经尝试了在这里和其他网站上找到的所有内容,但我似乎无法做到正确。

请帮助我!

编辑:我尝试在 viewDidAppear 中实现这行代码。我在某处的旧线程中找到了它,但它似乎不再起作用了......

[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];

最佳答案

我以编程方式创建了 map ,而不是使用 MapKit View ,它运行得非常好!

代码如下:

    [super viewDidLoad];

self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.mapView setShowsUserLocation:YES];
[self.mapView setDelegate:self];
[self.view addSubview:self.mapView];
[mapView setMapType:MKMapTypeHybrid];

}

#pragma mark - MKMapViewDelegate Methods

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

[self.mapView setRegion:MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.1f, 0.1))animated:YES];

}

关于ios - 如何放大和居中用户位置(Objective-C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30414968/

相关文章:

objective-c - 在 objective c 类中使用委托(delegate)调用 swift 方法

ios - 导航到 MKMapView 上的注释位置

ios - MKOverlayView 用混合模式绘制一些东西

ios - 在 iPhone 5s 或 64 位模拟器上测试 32 位 iOS 应用程序

ios - 无法快速符合 objective-c 协议(protocol)

ios - 显示 View 时 UITableView 变为非事件状态

ios - MKPolygon - 如何确定 CLLocationCoordinate2D 是否在 CLLocationCoordinate2D 多边形中?

objective-c - 动画 UIView 原点仅在第一次尝试后才有效

ios - 是否可以在保留计数不为零的对象上调用 dealloc?

iOS 自定义 map 、地理位置、 map 绘制等