项目中涉及到运动轨迹,不希望别人看到自己的运动轨迹时可以隐藏地图的底图。
使用MKPolygon可以在MKMapView上添加遮盖层,尝试添加一个覆盖全世界的polygon失败,猜想可能是因为东经180度和西经180度在地球上是同一条线所以添加失败,因此使用两个polygon来覆盖全球。
funccreatePolygon1() ->MKPolygon{
// render whole map view for map hidden
letpoint1 =CLLocationCoordinate2D(latitude:-90, longitude:0)
letpoint2 =CLLocationCoordinate2D(latitude:-90, longitude:180)
letpoint3 =CLLocationCoordinate2D(latitude:90, longitude:180)
letpoint4 =CLLocationCoordinate2D(latitude:90, longitude:0)
letpoints = [point1, point2, point3, point4]
returnMKPolygon(coordinates: points, count: points.count)
}
funccreatePolygon2() ->MKPolygon{
// render whole map view for map hidden
letpoint1 =CLLocationCoordinate2D(latitude:-90, longitude:-180)
letpoint2 =CLLocationCoordinate2D(latitude:-90, longitude:0)
letpoint3 =CLLocationCoordinate2D(latitude:90, longitude:0)
letpoint4 =CLLocationCoordinate2D(latitude:90, longitude:-180)
letpoints = [point1, point2, point3, point4]
returnMKPolygon(coordinates: points, count: points.count)
}