5

I am trying to use the containsLocation from the Google geometry library, but can't get it to 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 that points to a function in Google's lib. So I assume the problem should lie somewhere in this function.

dda
  • 6,030
  • 2
  • 25
  • 34
Neograph734
  • 1,714
  • 2
  • 18
  • 39

2 Answers2

6

Oke, stupid me

I was wrong using all the coords 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");
}
Neograph734
  • 1,714
  • 2
  • 18
  • 39
5

i had the same problem ([object Object]), I could solve that creating the polygon variable like that: draw = new google.maps.Polygon({paths:polyOptions});

Then the problem disappeared.

John Paul
  • 12,196
  • 6
  • 55
  • 75
user3037320
  • 51
  • 1
  • 1