Check start end end points are same in Google Map -
is there way check whether start , end positions same locations using google maps api v3.
here latitude , longitude ,
start point : 41.30395, -72.92671 end point : 41.3039500,-72.9267090
using latlng class's equals function: https://developers.google.com/maps/documentation/javascript/reference#latlng
var start = new google.maps.latlng(41.30395, -72.92671); var end = new google.maps.latlng(41.3039500,-72.9267090); alert(start.equals(end));
alternatively if want check 2 locations 'approximately' equal, define how many decimal places want round coordinates to. round coordinates compare them.
var startlat = start.lat(); var endlat = end.lat(); var startlng = start.lng(); var endlng = end.lng(); // round 3dp: startlat = startlat.tofixed(3); endlat = endlat.tofixed(3); startlng = startlng.tofixed(3); endlng = endlng.tofixed(3); console.log(startlat === endlat && startlng === endlng); console.log(startlat); console.log(endlat); console.log(startlng); console.log(endlng);
Comments
Post a Comment