如何在Google Maps iOS上添加多边形? [英] How can i add polygon on google maps IOS?

查看:92
本文介绍了如何在Google Maps iOS上添加多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Google地图视图上添加多边形,但是出现此错误

I want to add polygon on google maps view but I have this error

no visible @ interface GMSMapView declares the selector add overlay

代码:

CLLocationCoordinate2D commuterLotCoords[5]={
        CLLocationCoordinate2DMake(39.048019,-76.850535),
        CLLocationCoordinate2DMake(39.048027,-76.850234),
        CLLocationCoordinate2DMake(39.047407,-76.850181),
        CLLocationCoordinate2DMake(39.047407,-76.8505),
        CLLocationCoordinate2DMake(39.048019,-76.850535)
    };

MKPolygon *commuterPoly1 = [MKPolygon polygonWithCoordinates:commuterLotCoords count:5];
[mapView addOverlay:commuterPoly1];

推荐答案

对Dheeraj的回答略有更改:aka已更新为 Swift 4

Slight change to Dheeraj's Answer : aka Updated for Swift 4

func tempPolygons(){
    let polygon = GMSPolygon()
    let rect = GMSMutablePath()
    rect.add(CLLocationCoordinate2DMake(18.546160, 73.903992))
    rect.add(CLLocationCoordinate2DMake(18.546099, 73.904817))
    rect.add(CLLocationCoordinate2DMake(18.545922, 73.905643))
    rect.add(CLLocationCoordinate2DMake(18.545854, 73.905973))
    rect.add(CLLocationCoordinate2DMake(18.545105, 73.905915))
    rect.add(CLLocationCoordinate2DMake(18.543153, 73.904867))
    rect.add(CLLocationCoordinate2DMake(18.543016, 73.903805))
    rect.add(CLLocationCoordinate2DMake(18.545473, 73.903863))
    rect.add(CLLocationCoordinate2DMake(18.546140, 73.904013))

    polygon.path = rect
    polygon.fillColor = #colorLiteral(red: 0.9474907517, green: 0.2350950539, blue: 0.1785519123, alpha: 0.24)
    //polygon.strokeColor = UIColor.black
    polygon.strokeWidth = 0
    polygon.map = mapView
}

这篇关于如何在Google Maps iOS上添加多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆