C#:谷歌地图检查值是否在圈内? [英] C#: Google map check the value is inside the circle or not..?

查看:220
本文介绍了C#:谷歌地图检查值是否在圈内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
}

推荐答案

只需获得两点之间的距离,看看它是否在所需的半径范围内。



如果谷歌地图API没有这个功能(如果没有它会让我感到惊讶),你可以使用本文中的类来确定两个GPS点之间的距离。





一个方便的GPS类
[ ^ ]
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
[^]


这篇关于C#:谷歌地图检查值是否在圈内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆