I have to use Google Map for my iPhone project and I'am using GMSPolygon to draw a polygon but How can I fill everywhere on my map except the interior of the polygon. Like the image below.
Thank You.
I have played with your question. Main idea is to fill all Earth with polygon and then make holes for your particular area. Here is example code, but problem is that I can`t create polygon to cover whole Earth. First approach is to create 4 polygons for each quarter.
PGeoCountry is a struct with desired areas in boundariesPaths:[GMSPath]
func locateCountry(country: PGeoCountry) {
// 1. Create one quarter earth filling polygon
let fillingPath = GMSMutablePath()
fillingPath.addLatitude(90.0, longitude: -90.0)
fillingPath.addLatitude(90.0, longitude: 90.0)
fillingPath.addLatitude(0, longitude: 90.0)
fillingPath.addLatitude(0, longitude: -90.0)
let fillingPolygon = GMSPolygon(path:fillingPath)
let fillColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 0.6)
fillingPolygon.fillColor = fillColor
fillingPolygon.map = self.mapView
// 2. Add prepared array of GMSPath
fillingPolygon.holes = country.boundariesPaths
// 3. Add lines for boundaries
for path in country.boundariesPaths {
let line = GMSPolyline(path: path)
line.map = self.mapView
line.strokeColor = UIColor.blackColor()
}
}
Here is the result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With