我有一个存储用户信息(基本信息,地址信息等)的asp.net mvc应用程序。现在我需要的是,如果用户X搜索其他用户,然后使用他们的地址信息显示所有其他用户Y以及X和Y之间的距离。用户的地址信息包含地址,城市,州,邮政编码和国家。我对地理位置很陌生,谷歌地图。请建议我“如何计算asp.net mvc中两个地址之间的实际距离”。Asp.net mvc计算两个地址之间的距离
0
A
回答
2
来自http://www.geodatasource.com/developers/c-sharp
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::: :::
//::: This routine calculates the distance between two points (given the :::
//::: latitude/longitude of those points). It is being used to calculate :::
//::: the distance between two locations using GeoDataSource(TM) products :::
//::: :::
//::: Definitions: :::
//::: South latitudes are negative, east longitudes are positive :::
//::: :::
//::: Passed to function: :::
//::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
//::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
//::: unit = the unit you desire for results :::
//::: where: 'M' is statute miles :::
//::: 'K' is kilometers (default) :::
//::: 'N' is nautical miles :::
//::: :::
//::: Worldwide cities and other features databases with latitude longitude :::
//::: are available at http://www.geodatasource.com :::
//::: :::
//::: For enquiries, please contact [email protected] :::
//::: :::
//::: Official Web site: http://www.geodatasource.com :::
//::: :::
//::: GeoDataSource.com (C) All Rights Reserved 2014 :::
//::: :::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta = lon1 - lon2;
double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
if (unit == 'K') {
dist = dist * 1.609344;
} else if (unit == 'N') {
dist = dist * 0.8684;
}
return (dist);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:: This function converts decimal degrees to radians :::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private double deg2rad(double deg) {
return (deg * Math.PI/180.0);
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:: This function converts radians to decimal degrees :::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private double rad2deg(double rad) {
return (rad/Math.PI * 180.0);
}
Console.WriteLine(distance(32.9697, -96.80322, 29.46786, -98.53506, "M"));
Console.WriteLine(distance(32.9697, -96.80322, 29.46786, -98.53506, "K"));
Console.WriteLine(distance(32.9697, -96.80322, 29.46786, -98.53506, "N"));
0
首先,你需要与谷歌地图API来获取你的地址的客户端的坐标。 这是可以做到这样的: http://dotnet.dzone.com/news/using-google-geocode-get-gps
然后你就可以得到2个坐标之间的距离:
var pointA = DbGeography.FromText("POINT (-2.232121 53.477724)", 4326);
var pointB = DbGeography.FromText("POINT (-2.231105 53.478121)", 4326);
var distanceAB = pointA.Distance(pointB); //distanceAB = 80.6382796064941 metres
相关问题
- 1. 两个地址之间的距离
- 2. 计算没有Google地图的地址之间的距离
- 3. 计算两次之间的距离
- 4. 两地的距离计算
- 5. 如何计算两个地理点之间的距离
- 6. 用于计算两个地址之间距离的现有服务有哪些?
- 7. 如何使用Google Maps API计算两个地址之间的驾驶距离?
- 8. 两个地址之间的直线距离 - Google地图API
- 9. 如何计算谷歌地图中两点之间的距离?
- 10. 计算bing地图中两点之间的距离
- 11. 如何使用php计算两地之间的距离?
- 12. 如何计算两地之间的距离?
- 13. 两个地理点之间的距离?
- 14. 距离之间的两个
- 15. 计算pyspark中两个数据帧的行之间的距离
- 16. 最快的方法来计算两个CGPoints之间的距离?
- 17. 计算两个字符串之间的levenshtein距离
- 18. 如何计算像素中两个物体之间的距离?
- 19. 如何计算ArrayList中两个标记之间的距离?
- 20. 计算两个用户之间的社交距离
- 21. 计算两个x/y坐标之间的距离?
- 22. 如何计算两个直方图之间的距离
- 23. 计算两个GPRS坐标之间的距离
- 24. 如何使用Android MapView计算两个GeoPoint之间的距离
- 25. 计算两个点之间的距离iphone
- 26. 我如何计算Java中两个gps点之间的距离?
- 27. 我们如何计算两个坐标之间的距离。 ArangoDB
- 28. 如何有效计算两个向量之间的距离?
- 29. 如何计算GraphX,Scala中两个节点之间的距离?
- 30. 两个阵列之间的余弦距离计算 - Python
堆栈溢出的答案应该是独立的,即使它们的链路断开。您应该在答案中包含该链接的相关内容。 – 2015-03-08 03:41:37