我想在Google地图视图上添加多边形,但是出现此错误
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
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
}