gpt4 book ai didi

ios - 使用 iOS 版谷歌地图在多边形中添加孔

转载 作者:行者123 更新时间:2023-11-29 02:16:42 25 4
gpt4 key购买 nike

我想在我的应用程序中将整个 map 变暗,但正常显示的小“选定”部分除外。

为了在 Google Maps API for Android 中实现该功能,我创建了一个多边形并调用了 setHoles 函数,如下所示:

List points = Arrays.asList(new LatLng(-90 + delta, -180 + delta),
new LatLng(-90 + delta, 0),
new LatLng(-90 + delta, 180 - delta),
new LatLng(0, 180 - delta),
new LatLng(90 - delta, 180 - delta),
new LatLng(90 - delta, 0),
new LatLng(90 - delta, -180 + delta),
new LatLng(0, -180 + delta));
defaultZone = map.addPolygon(new PolygonOptions().addAll(points));
defaultZone.setFillColor(0x99000000);

defaultZone.setHoles(Arrays.asList(pointsLatLong));

这对 Android 非常有用,我想在 iOS 应用程序中重现相同的效果,但是 GMSPolygon 类没有setHoles 函数,我不知道如何在多边形中创建孔(我试图在 map 上绘制深色多边形,然后在其上方绘制带有透明颜色的“选定”区域,但是它确实行不通)。

有人可以帮助我吗?这似乎很奇怪,一个功能可以在 Android 中完成,但不能在 iOS 中使用相同的框架

最佳答案

迅速

override func loadView() {
let hydeParkLocation = CLLocationCoordinate2D(latitude: -33.87344, longitude: 151.21135)
let camera = GMSCameraPosition.camera(withTarget: hydeParkLocation, zoom: 16)
let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
mapView.animate(to: camera)

let hydePark = "tpwmEkd|y[QVe@Pk@BsHe@mGc@iNaAKMaBIYIq@qAMo@Eo@@[Fe@DoALu@HUb@c@XUZS^ELGxOhAd@@ZB`@J^BhFRlBN\\BZ@`AFrATAJAR?rAE\\C~BIpD"
let archibaldFountain = "tlvmEqq|y[NNCXSJQOB[TI"
let reflectionPool = "bewmEwk|y[Dm@zAPEj@{AO"

let polygon = GMSPolygon()
polygon.path = GMSPath(fromEncodedPath: hydePark)
polygon.holes = [GMSPath(fromEncodedPath: archibaldFountain)!, GMSPath(fromEncodedPath: reflectionPool)!]
polygon.fillColor = UIColor(colorLiteralRed: 1.0, green: 0.0, blue: 0.0, alpha: 0.2)
polygon.strokeColor = UIColor(colorLiteralRed: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)
polygon.strokeWidth = 2
polygon.map = mapView
view = mapView
}

objective-c

- (void)loadView {
CLLocationCoordinate2D hydeParkLocation = CLLocationCoordinate2DMake(-33.87344, 151.21135);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:hydeParkLocation
zoom:16];
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];

NSString *hydePark = @"tpwmEkd|y[QVe@Pk@BsHe@mGc@iNaAKMaBIYIq@qAMo@Eo@@[Fe@DoALu@HUb@c@XUZS^ELGxOhAd@@ZB`@J^BhFRlBN\\BZ@`AFrATAJAR?rAE\\C~BIpD";
NSString *archibaldFountain = @"tlvmEqq|y[NNCXSJQOB[TI";
NSString *reflectionPool = @"bewmEwk|y[Dm@zAPEj@{AO";

GMSPolygon *polygon = [[GMSPolygon alloc] init];
polygon.path = [GMSPath pathFromEncodedPath:hydePark];
polygon.holes = @[[GMSPath pathFromEncodedPath:archibaldFountain],
[GMSPath pathFromEncodedPath:reflectionPool]];
polygon.fillColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.2];
polygon.strokeColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
polygon.strokeWidth = 2;
polygon.map = _mapView;
self.view = _mapView;
}

reference

关于ios - 使用 iOS 版谷歌地图在多边形中添加孔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28671855/

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