0

I am trying to set up a system that loads a KMZ file and displays it using google maps and then tests if the user has clicked within the bounds of a polygon created by the KMZ. I have searched all through these forums and the web and haven't found a working solution.

I am having no problem loading and reading the KMZ file and the polygon is displaying perfectly on the map. But when I try to use the polygon data returned by geoXML3 to test if a location is within the bounds then I get a variety of errors depending on how I approach it. I am loading the geoxml3.js files locally and the parser for the KMZ files, and as I say that works fine so I won't include all that. The KMZ file is local to the server and reads fine.

This is what I have:

<script>
var zone;
var polzone;
function initMap() {
   var map = new google.maps.Map(document.getElementById('map'), {
     zoom: 11,
     center: {lat: 0, lng: 0}
   });

  zone = new geoXML3.parser({map: map});
  zone.parse('test.kmz');
}

function testlimit(){
  polzone = zone.docs[0].gpolygons[0];
  console.log( google.maps.geometry.poly.containsLocation(new google.maps.LatLng("0", "0"), polzone));

}
</script>

As you can see I'm testing just with hard coded long and lattitude values and it's giving me the error "Uncaught TypeError: b.get is not a function". The testlimit function is fired when a button is clicked.

I initially had more code but as it wasn't working, this is where I've ended up. Any help would be appreciated.

user1770717
  • 309
  • 1
  • 12
  • 1
    Can you create a fiddle demonstrating your issue? – xkcd149 Mar 01 '16 at 14:14
  • OK I tried to do that, I just wasn't sure how to load a kmz file into there. – user1770717 Mar 01 '16 at 14:17
  • It seems the problem is specifically with calling the polygon from the geoXML object. How is one supposed to fetch a google maps polygon from the object created by the geoXML3 parser. Sorry if it's a stupid question, but I've never used it before and there is very little documentation online on how it all works. – user1770717 Mar 01 '16 at 14:35

1 Answers1

0

Alright, never mind then, Apparently the gpolygon variable is an array. So it should be polzone = zone.docs[0].gpolygons[0];

One of those days I should have stayed in bed I guess...

user1770717
  • 309
  • 1
  • 12