我想在谷歌地图视图上添加多边形,但我有这个错误
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];
答案 0 :(得分:1)
GMSPolygon * polygon = [[GMSPolygon alloc] init];
GMSMutablePath * rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(39.048019,-76.850535)];
[rect addCoordinate:CLLocationCoordinate2DMake(39.048027,-76.850234)];
[rect addCoordinate:CLLocationCoordinate2DMake(39.047407,-76.850181)];
[rect addCoordinate:CLLocationCoordinate2DMake(39.047407,-76.8505)];
[rect addCoordinate:CLLocationCoordinate2DMake(39.048019,-76.850535)];
polygon.path=rect;
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.2f];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = mapView;
答案 1 :(得分:1)
Swift 2.2:
let polygon = GMSPolygon()
let rect = GMSMutablePath()
rect.addCoordinate(CLLocationCoordinate2DMake(22.7196, 75.8577))
rect.addCoordinate(CLLocationCoordinate2DMake(22.7396, 75.8577))
rect.addCoordinate(CLLocationCoordinate2DMake(22.7196, 75.1577))
rect.addCoordinate(CLLocationCoordinate2DMake(22.9196, 76.8577))
rect.addCoordinate(CLLocationCoordinate2DMake(22.9196, 75.8577))
rect.addCoordinate(CLLocationCoordinate2DMake(23.7196, 77.8577))
polygon.path = rect
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.2)
polygon.strokeColor = UIColor.blackColor()
polygon.strokeWidth = 2
polygon.map = mapView
答案 2 :(得分:1)
对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
}
答案 3 :(得分:0)
要在GoogleMap上绘制多边形,您应该使用GMSPolygon类。 绘制多边形的步骤:
在Apple Map上绘图
相同的步骤适用于Polyline。