Exception in template helper: TypeError: b.get is not a function

Hi,
maybe someone can see whats wrong here?
I have this helper, but i get that error:
“Exception in template helper: TypeError: b.get is not a function”
//helper
inPolygon: function(RefId){
console.log(RefId); //ok
var cursor = Polygons.find({RefId:RefId});
cursor.forEach( function(zonePolygon) {
console.log(zonePolygon.zoneString); // ok
var decodedPath = google.maps.geometry.encoding.decodePath(zonePolygon.zoneString);
console.log(decodedPath); //ok
var curPosition = new google.maps.LatLng(32.0680324, 34.8027191);
return google.maps.geometry.poly.containsLocation(curPosition, decodedPath) ? true : false;
});
}

Thanks.

Your code snippet doesn’t show anything that lines up with the exception (no b variable, no get function call), which means it’s happening elsewhere. Can you paste in the full exception stack trace?

Thanks. This one is in google map apis:
that’s where the error points to:
!b.get(“geodesic”),e=b.get(“latLngs”),f=b.get(“map”),

https://maps.googleapis.com/maps-api-v3/api/js/24/6a/geometry.js

Okay - so b is the second parameter of the containsLocation function. Whatever your passing into the containsLocation function for decodedPath doesn’t have an available get function. Double check the value of decodedPath and make sure it’s the proper object containsLocation is expecting.

1 Like

Great I’ll check that.
May I also ask, assuming I wanted the loop to stop after returning true, what would I do?

forEach wasn’t designed to be broken out of. If you want to loop over the items in the cursor, and break when something happens, maybe consider first getting the cursor docs as an array (using cursor.fetch()), then loop over them using a standard for loop (breaking when you want to).

1 Like