查找(指定地点的纬度和经度)和DB(存储的)纬度和经度之间的距离 [英] find distance between (latitude and longitude of specifie place,)) and DB(stored) latitude and longitude

查看:98
本文介绍了查找(指定地点的纬度和经度)和DB(存储的)纬度和经度之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个asp.net Web应用程序,以便根据指定地点的经度和纬度查找5公里范围内的其他附近地点.我在数据库中有某些地方的经度和纬度.我需要代码来计算两点之间的距离(指定它们的纬度/经度


问候

I need write a asp.net web application in this need to find other nearby places within 5 km distance based on the latitude and longitude of the specified place. I have latitude and longitude of some places in my database. I need code to calculate the distance between two points (specifying their latitude/longitude


regards

推荐答案

pradeep kumar patwari写道:
pradeep kumar patwari wrote:

我找到了一些代码来计算两点之间的距离(指定其纬度/经度

I found some code to calculate the distance between two points (specifying their latitude/longitude



您想要一些东西,甚至有一个代码.怎么办?

在此处查看如何发布问题: http://www.codeproject.com/script/Answers /Post.aspx?new=question [ ^ ]

除非您不告诉我们您的问题是什么,否则我们应该如何知道并回答它们?



You wanted something, you even got a code. Now what?

Look here of how to post a question: http://www.codeproject.com/script/Answers/Post.aspx?new=question[^]

Until unless you wont tell us what is your issue, how are we suppose to know and answer them?


using System;

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"));


这篇关于查找(指定地点的纬度和经度)和DB(存储的)纬度和经度之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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