How to use containsLocation in Google maps geometry library.

I am trying to use containsLocation in a Google geometry library but cannot make it work ...

 var point = new google.maps.LatLng(51.331, 3.538); var poly = [ new google.maps.LatLng(51.401818509550615, 3.547626782103622), new google.maps.LatLng(51.397574277049365, 3.563607598960424), new google.maps.LatLng(51.398540111384975, 3.567880788749134), ... // it is a lot bigger ]; if(google.maps.geometry.poly.containsLocation(point, poly) == true) { alert("yes"); } 

The Javascript console gives an error, but it points to a function in Google lib. Therefore, I assume that the problem should be somewhere in this function.

+4
source share
2 answers

Oke, silly me

I made a mistake using all the coordinates as an array, I had to use the created polygon object.

 var polyOptions = { ... } draw = new google.maps.Polygon(polyOptions); draw.setMap(map); if(google.maps.geometry.poly.containsLocation(point, draw) == true) { alert("yes"); } 
+5
source

I had the same problem ([object Object]) , I could decide that creating such a polygonal variable: draw = new google.maps.Polygon({paths:polyOptions});

Then the problem disappeared.

+4
source

Source: https://habr.com/ru/post/1415396/


All Articles