Reputation: 1859
While trying to compare 2 Google Map LatLngs to see if they were the at the same coordinates, I found that ===
and ==
don't work.
I know the points are the same because I've tested it with the same values and calculated the distance between them which requires the inclusion of the Google Map's Geometry library. I know I can check if the distance between them is 0 units to see if they are the same but I'd rather leave the library out if I could.
My test: JSFiddle
Is is possible to compare them using basic JavaScript? If not, what is the simplest way of comparing 2 Google Map LatLngs?
Upvotes: 1
Views: 66
Reputation: 15593
You need to convert them in string by using the toString()
of JS:
if (pos1.toString() == pos2.toString()) {
alert("Equal");
} else {
alert("Not Equal");
}
As pos1 and pos2 has the value like: (-45,108) and to compare it you need to use toString()
function.
Here is working JSFIDDLE.
Upvotes: 1