使用谷歌地图为ios添加多边形孔

时间:2015-02-23 10:41:30

标签: ios google-maps google-maps-sdk-ios

我希望在我的应用程序中使整个地图变暗,除了小的选择"正常显示的部分。

要在 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类没有{{1}函数,我无法弄清楚如何在多边形中创建孔(我试图在地图上绘制暗多边形,然后绘制"选择"区域,上面有透明颜色但它吸食了鼻涕。)

有人能帮助我吗?一个功能可以在 Android 中完成,而不是在 iOS 中使用相同的框架

,这似乎很奇怪

3 个答案:

答案 0 :(得分:0)

这是iOS SDK的已知限制。正在跟踪请求:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=5464

投票吧!

答案 1 :(得分:0)

这是一个众所周知的请求,谷歌将最有可能在下一个iOS地图SDK发布中包含。

在此链接上发表评论https://code.google.com/p/gmaps-api-issues/issues/detail?id=5464

答案 2 :(得分:0)

迅速

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
}

目标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