Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
 
 
     I need to find the the latitude langitude value is inside the Radius circle or not.if its is outside i have to pass some value from my MVC Controller. 
 
 




i have tried this but data comes wrong distance,

if the distance is acroos from the radius line i have to show some notification. if anybody knows this please help me for the same

Thanks,


What I have tried:

function distance(lat1,lon1,lat2,lon2){
  var R = 6371; // Earth's radius in Km
  return Math.acos(Math.sin(lat1)*Math.sin(lat2) + 
                  Math.cos(lat1)*Math.cos(lat2) *
                  Math.cos(lon2-lon1)) * R;
}


if (distance(user.lat, user.lon, post.lat, post.lon) <= desiredRadiusInKm){
  // return true;
} else {
  // return false;
}
Posted
Updated 15-Mar-18 2:23am

1 solution

Simply get the distance between two points, and see if it's within the desired radius.

If the Google Maps API doesn't have a function for that (and it would honestly surprise me if it didn't), you can use the class in this article to determine the distance between two GPS points.


A Handy GPS Class
[^]
 
Share this answer
 
v2
Comments
Member 11183217 15-Mar-18 8:41am    
hi john i have done i got the result. nothing has been change. simply i have passed my two points. manually i checked the result has come what i am expected. thanks you so much for your kind responce

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900