I am having an issue where I have an xml file of latlong points that I am trying to determine using containsLocation() if the current position of the user is within the boundaries. The boundaries is the 11th district of NC.
I am using the method and it is not throwing any errors, but it simply returns false every time whether the user is inside those boundaries or not. To create my object array to pass to containsLocation, I use a series of replace() methods and then turn it into an object using JSON.parse. I then use these two methods to attempt to pass the array to containsLocation.
function createGoogleMapsPolygon(parxyObject) {
var myObject = parxyObject;
var coordsArray = xyObjectToArray(xyObject);
var polygon;
polygon = new google.maps.Polygon({
paths: coordsArray
});
return polygon;
}
function xyObjectToArray(parxyObject) {
//splice last element out for TESTING
var coordsArray = [];
var myObject = parxyObject;
for (var i = 0; i < (myObject.length - 1); i++) {
coordsArray[i] = new google.maps.LatLng(myObject[i].x, myObject[i].y);
}
console.log("First Element: " + coordsArray[0] + " Last Element: " + coordsArray[coordsArray.length - 1]);
return coordsArray;
}
I use - 1 because the parameters specifications for the object of containsLocation() calls for me to not use the last point as the first point the the object array. I have tried it both ways; neither way works.
After all of this code has executed, it returns:
{"gm_accessors_":{"latLngs":null,"visible":null},"latLngs":{"j":[{"j":[{"k":-84.321797,"B":34.98896500000001},{"k":-84.321582,"B":34.990639999999985}, ...
... {"k":-84.320918,"B":34.98840599999994},{"k":-84.321869,"B":34.988407999999936}],"gm_accessors_":{"length":null},"length":15249,"gm_bindings_":{"length":{}}}],"gm_accessors_":{"length":null},"length":1,"gm_bindings_":{"length":{}}},"gm_bindings_":{"latLngs":{},"visible":{}},"visible":true}
The current position object needed to pass is constructed in the same format as described above. As I mentioned, there are over 500 of these points, maybe even over 1000, so I do not know if this is what is breaking the code.
Keep in mind that it does not throw an error of any kind. It just returns false 100% of the time. I set inDistrict variable to null on purpose instead of false to see if the function was returning the false, and it is.
I don't know what the problem is, if it is a refreshing problem, to many objects, or just something that I have done wrong, but any help would be great!
Thanks.
No comments:
Post a Comment