‫In this tutorial, we are going to work with polygons in Google Maps.
‫Hello guys, and welcome to the Complete Android Developer course and the Master coding Channel.
‫We will learn how to create and customize polygons and Google Maps.
‫We have learned about Polylines.
‫So polygons are objects are similar to polyline objects in that they consist of a series of coordinates
‫in an ordered sequence.
‫However, instead of being open ended, polygons are designed to define regions within a closed loop
‫with the interior field.
‫So let's jump to our coding playground.
‫And let's create a polygon.
‫Here we go.
‫Polygons.
‫Now, in the same way of polygons, we are going to create a polygon option.
‫Called rect option and new polygons.
‫Polygon options.
‫And in the same way I will add M1 and M2 and I will add also M3.
‫M4 and I will add AM5.
‫Okay.
‫In this way, we have created the polygon option.
‫And get back the mutable polygon.
‫Polygon.
‫Class Polygon equal new polygon.
‫I will import the class and I will pass the rec option.
‫Sorry here.
‫Not new.
‫It is called m map dot polygon add polygon and I will pass rect option.
‫Now let's run our virtual device emulator and see what's happening.
‫So.
‫Okay.
‫So it is a drone as a closed set.
‫As I told you, it is a closed set.
‫It's not like polylines.
‫It is closed.
‫Set.
‫Now to alter the shape of the polygon after it has been added, you can call polygon dot set points
‫and provide a new list of the points for the outline of the polygon.
‫So.
‫Polygon, equal dot map dot add polygon.
‫And we can specify here the fill color.
‫So there are the same way as polylines.
‫Polygons have also some characteristics and some methods that we can use and they are very useful.
‫So I will use the fill color.
‫The fill color.
‫I will create color dot blue.
‫Let's see.
‫Color that blue.
‫Let's run.
‫And here we go.
‫It is the polygon that we have created.
‫Let's edit this.
‫This is let's make it zero zero.
‫In order to see the shape more more confident and more accurate.
‫Okay, It is.
‫The polygon.
‫Okay, now let's see.
‫You can stroke color.
‫We can edit it.
‫Color dot red.
‫Let's see.
‫The stroke color, which is the the outer color.
‫Okay.
‫This is the red stroke color.
‫And the fill color is red.
‫Sorry is blue.
‫So.
‫In order to add also like a hole you can create also inside it add whole.
‫Here we can add a whole which is which is let's see a a multiple paths like multiple paths that can
‫be combined in a single polyline object to create complex shapes such as rings or donuts like islands.
‫Complex shapes are always the composition of multiple, simpler paths.
‫So two paths paths must be defined in the same area.
‫The larger of the two regions defined the fill area and the simple polygon with no addition option.
‫What I'm talking.
‫I'm talking about making holes in the inside.
‫The the polygon that we have created so that long you can specify it here or you can specify it in the
‫same way that I have created.
‫New that long.
‫I will create that like two to.
‫Let's create another whole new lat long and two.
‫One.
‫Okay.
‫This is called the whole.
‫And what we have is making like this.
‫So.
‫For color.
‫I remove like this.
‫And.
‫This way.
‫We have created it now.
‫We have created a hole.
‫One hole the second lat long and the third lat long.
‫Let's create another one new hole lat long and create it as.
‫Uh, one.
‫One.
‫So.
‫One and one.
‫Okay.
‫This will make it clear.
‫Method.
‫The whole class polygon could not be applied for given types.
‫Required iterator iterable.
‫Okay.
‫We need to make a list of lat long.
‫We can specify it here.
‫Like a list.
‫Like a list or iterable class.
‫You can specify them here.
‫So in this way we have learned that adding a hole inside the polygon, we can specify a creating an
‫array list.
‫So for that I will create an array list which is an of type that extends iterable and an array list.
‫I will create a create array list of type lat long and we call it it as let T and the new array list
‫list and let t it will add the lat longs.
‫So I will create a lat lungs called M6 equal new lat long new lat long and I will create zero zero.
‫Lat long
‫m7 equal five zero lat long m8 equal new lat long.
‫Zero 5 or 5 five and lat long m9 equal new lat long and it is called.
‫A05.
‫I will need to create it as a box.
‫So let's see.
‫I will add this points to the array list called M.
‫Six latte dot add m7
‫and latte dot add m8.
‫And latte dot add M nine.
‫Okay, so guys, if you need to add the hole inside the the polygon, you need to make an array list
‫this array list of type iterable.
‫And we add here, as I was talking about called add hole and we specify the array list called latte.
‫Let's run and see.
‫Okay, guys, this is the our polygon and this is our square.
‫So I will create a big box.
‫Let's see.
‫Here.
‫I will make them like more.
‫More specific.
‫One and two.
‫Let's I remove this M2, m3, m4 M5.
‫Let's see if it is still working.
‫Okay.
‫Still working.
‫So you can add in the in this way the points I will create now a big hole called like
‫-20.
‫-20, start with -20.
‫It will go to 20 and still on -20.
‫It will go back to 20 and 20.
‫Here And it will go back to -20 or sorry, 20 and.
‫-20.
‫20.
‫Two.
‫-20.
‫At 22, 20 and -20.
‫Here.
‫And still here.
‫20.
‫I will remove this and go back for here and click Run.
‫It should be a big box inside a box.
‫Okay, so here we go.
‫It is now working.
‫Okay, guys, it's very clear and very simple.
‫Using the holes and using the Polygons and Android studio.
‫Also just a one mark remark.
‫It is you can use allow for clicking the polygon by creating a polygon click listener.
‫So use on polygon click listener and implement this interface Alt+ insert implement the methods and
‫you can use the on polygon click.
‫Also, as I told you, polygons and Polylines click listeners are not usable usable because they there
‫is less use of them because not real reliable and they are not effective and they useless.
‫So guys, till now we are doing well.
‫We are going to to be a professional in Google Maps and we are doing very, very well.
‫Thank you guys.
‫I hope you subscribe if you want us to make a continue making tutorials, just subscribe to our YouTube
‫channel.
‫Hit like comment below saying thanks and we will be motivated to make and produce many and many courses
‫and many tutorials.
‫Hydra error Error rate five stars on Udemy.
‫You get free coupons.
‫See you guys next.
‫Videos.
‫Next videos.
‫Next.