I'm a beginner in JavaScript. Recently I'm trying to develop associative applications in Google Map. But I bump into a strange problem.
Please refer to the code below.
<html>
<head>
<script src = "http://maps.googleapis.com/maps/api/js"></script>
</head>
<body>
<script>
var buf = [];
var pos1 = new google.maps.LatLng(1, 2); buf.push(pos1);
var pos2 = new google.maps.LatLng(3, 4); buf.push(pos2);
var pos3 = new google.maps.LatLng(5, 6); buf.push(pos3);
//initialize a new object here
var pos4 = new google.maps.LatLng(3, 4);
if ( buf.indexOf(pos4) != -1 )
document.write("yes");
else
document.write("no");
</script>
<body>
</html>
Because value of pos4
is same to pos2
, the printed result should be "yes" if the position does exist in the array. However it printed "no" on the screen.
I 've tried to print out the values from pos4
and pos2
. I found that both are the same and I have no idea why this check failed. Is there any solution to solve the problem?