3
votes

I have a json file with plenty GPS coordinates (lat,lng) which will be displayed as marker in Google Maps. Now I want to check whether the user is close to a marker - let's say 10 meters.

My approach was to simply compare the users current location (lat/lng) with my json array. For this I would have to calculate the actual radius for each marker which I find quite difficult to map to lat/lng.

Anyways, I'm not that familiar with Google Maps API and couldn't figure out myself whether there is already some function for this.

Thanks, Dennis

1

1 Answers

3
votes

You can create function like this and find out distance.

function getDistance(source, destination) {
  return google.maps.geometry.spherical.computeDistanceBetween(
    new google.maps.LatLng(source.lat, source.lng),
    new google.maps.LatLng(destination.lat, destination.lng)
  );
}

With distance you can write your further logic. Hope this will help.