如何像 Apple Map 应用程序一样获取 MapKit 位置的卫星图像?
How can I fetch a satellite image of the MapKit location as Apple Map app does?
在我的应用程序中,我有一个具有自动完成功能的 MapView。当用户选择某个地方时,我会在地图视图上使用 details
按钮显示一个图钉。然后我想显示该地点的静态卫星图像,就像 Apple 的地图应用程序一样。
有什么方法可以做到这一点吗?
MKMapView
有一个 属性 mapType
。将此 属性 设置为 MKMapType.Satellite
。
可能的类型是:
- 标准
- 卫星
- 混合
如果您想在 MapView
上创建所选位置的静态图像,您可以像这样对详细视图控制器使用 MKMapSnaphotter class for this purpose with satellite map type. When you click on the details button, pass MKSnapshotOptions:
MKMapSnapshotOptions *options = [MKMapSnapshotOptions new];
options.region = mapView.region;
options.size = mapView.frame.size;
options.mapType = MKMapTypeSatellite;
options.showsBuildings = YES;
options.scale = [[UIScreen mainScreen] scale];
detailViewController.options = options;
然后在您的详细视图控制器中创建一个快照图像并像这样显示它:
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) return; //And show error message;
imageView.image = snapshot.image;
}];
在我的应用程序中,我有一个具有自动完成功能的 MapView。当用户选择某个地方时,我会在地图视图上使用 details
按钮显示一个图钉。然后我想显示该地点的静态卫星图像,就像 Apple 的地图应用程序一样。
有什么方法可以做到这一点吗?
MKMapView
有一个 属性 mapType
。将此 属性 设置为 MKMapType.Satellite
。
可能的类型是:
- 标准
- 卫星
- 混合
如果您想在 MapView
上创建所选位置的静态图像,您可以像这样对详细视图控制器使用 MKMapSnaphotter class for this purpose with satellite map type. When you click on the details button, pass MKSnapshotOptions:
MKMapSnapshotOptions *options = [MKMapSnapshotOptions new];
options.region = mapView.region;
options.size = mapView.frame.size;
options.mapType = MKMapTypeSatellite;
options.showsBuildings = YES;
options.scale = [[UIScreen mainScreen] scale];
detailViewController.options = options;
然后在您的详细视图控制器中创建一个快照图像并像这样显示它:
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:self.options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (error) return; //And show error message;
imageView.image = snapshot.image;
}];