vendredi 7 octobre 2016

`if ( ...contains(arrayOfLatLngObjects[i]) )` producing TypeError: a.lat is not a function

It has proven nearly impossible to find relevant information about this particular error. Below is the relevant and initial code that I was using which generates this error:

var businesses = [
    {lat: 49.240020, lng: -123.076069},
    {lat: 49.251947, lng: -123.167336},
    ...
];
var withinBounds = [];
function getMapBounds() {
    mapBounds = myMap.getBounds();
    for (var i = 0; i < businesses.length; i++) {
        if (latLngClass.contains(businesses[i])) { // the condition is generating the error
            withinBounds.unshift(businesses[i]);
        };
    };
};

After doing some digging around in the documentation, I realized that .contains() is a method of the LatLngBounds class, so I assumed that this is what was causing the issue. However, I changed the code above to reflect the code below, but I'm still receiving the exact same error from the if (condition).

    ...
    var latLngClass = new google.maps.LatLngBounds(mapBounds.lat, mapBounds.lng);
    for (var i = 0; i < businesses.length; i++) {
        if (latLngClass.contains(businesses[i])) {
            ...

I'm absolutely dumbfounded now. Thanks in advance for any help!

Aucun commentaire:

Enregistrer un commentaire