- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试获取两个位置的距离,我真的需要使用 mySQL 完成此操作,因为我必须过滤大量记录。不幸的是,mysql 语句的结果与 google maps 的结果不同。可能是什么原因。
我的 Mysql 语句是 (Values hardcoded)
SELECT ((ACOS(SIN(6.914556 * PI() / 180) * SIN(6.913794 * PI() / 180) + COS(6.914556 * PI() / 180) * COS(6.913794 * PI() / 180) * COS((79.973194- 79.97330) * PI() / 180)) * 180 / PI()) * 60 * 1.609344 * 1000) AS `distance`
我得到 74.27 米作为距离。
然后我使用了我发现的另一个 SQL 语句,它给出了 85.53 米。
SELECT (1.609344 * 1000 * 3959 * acos( cos( radians(6.914556) ) * cos( radians( 6.913794 ) ) * cos( radians( 79.97330 ) - radians(79.973194) ) + sin( radians(6.914556) ) * sin( radians( 6.913794) ) ) ) AS distance
但是如果我使用 google API
我得到的距离是 28 米。
无论如何我可以解决这个问题。我需要一个在 MySQL 端工作的解决方案。感谢您的所有支持。
编辑:
我尝试过使用 PHP,但我仍然存在距离差异。
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
}
else if ($unit == "M") {
return ($miles * 1.609344 * 1000);
}else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}
}
function getDrivingDistance($inLatitude,$inLongitude,$outLatitude,$outLongitude)
{
if(empty($inLatitude) || empty($inLongitude) ||empty($outLatitude) ||empty($outLongitude))
return 0;
// Generate URL
$url = "http://maps.googleapis.com/maps/api/directions/json?origin=$inLatitude,$inLongitude&destination=$outLatitude,$outLongitude&sensor=false";
// Retrieve the URL contents
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
$jsonResponse = curl_exec($c);
curl_close($c);
$dataset = json_decode($jsonResponse);
if(!$dataset)
return 0;
if(!isset($dataset->routes[0]->legs[0]->distance->value))
return 0;
$distance = $dataset->routes[0]->legs[0]->distance->value;
return $distance;
}
echo distance(6.914556,79.973194,6.913794,79.97330,'M') . "<br>";
echo getDrivingDistance(6.914556,79.973194,6.913794,79.97330);
?>
最佳答案
我试过大圆公式,结果是 85.5m(你的公式不太正确,但很接近)。与谷歌的不同之处在于,谷歌试图计算道路上两点的距离,以某种方式将一个点投影到道路上。见下图。 (红线是根据坐标绘制的,距离为 85.5m,蓝线是谷歌渲染的,不知何故被“捕捉”到道路上)
关于php - 用经度和纬度计算距离有不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18459179/
所以:我有以下函数,改编自在线找到的公式,它采用两个纬度/经度坐标并计算它们之间的距离(以英里为单位)(沿着球形地球): public static double distance (double l
我有一个给定点(经度、纬度),我想获取给定点 5 英里半径范围内的所有点范围? 最佳答案 我只是在这里猜测,但我认为您需要找到一种不同的方法。如果您尝试使用 Foursquare、Google map
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我找到了一些代码,用于将纬度/经度转换为给定图像上的像素,反之亦然。我将其移植到 JavaScript,但在纬度上得到了不正确的返回值。我测试了原始的、未修改的代码,它给出了同样的不准确之处。下面是带
我正在考虑使用 rChart/LeafLet 为我所在县的房屋销售创建一个 Shiny 的应用程序。在任何给定时间,都有数百套房屋出售。想要为所有人绘制街道地址到地理位置(纬度/经度)的 map 并将
是否有任何方法(任何 API 或任何 URL)仅通过传递区号(邮政编码)来查找经纬度? 最佳答案 Google map 地理编码器将仅根据邮政编码进行搜索。 这是一个例子:(和一个 fiddle 来查
我正在尝试使用 openlayers 中的方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用: var topleft = vectors.f
下面的代码将在 map 中添加一个标记并在警报中显示其纬度/经度。 var note = document.getElementById('note'); var datepick = documen
如何将地址或城市转换为纬度/经度?我可以从哪些商业机构“租用”这项服务?这将用于具有全时互联网访问的 Windows PC 上的商业桌面应用程序。 最佳答案 Google 有一个地理编码 API,对于
我的地理位置字符串为 25°9'37"N 55°13'28"E。使用 JavaScript Regex 我想从上面的字符串中提取 Lat 和 Lng。谢谢。 最佳答案 Your first row c
考虑在 map 上有一个圆,其中心为 GLatLng (A),半径 (r) 以米为单位。 如何计算B位置的GLatLng?假设r平行于赤道。 使用 GLatLng.distanceFrom() 方法在
我有 CLLocation 对象,其中包含用户的当前位置,并且对于可以倾斜的矩形的每个角,我有 4 个纬度/经度对。现在我想检查 CLLocation 坐标是否在该矩形内。 以下是矩形的坐标 #def
我正在尝试使用以下代码获取用户当前的纬度/经度: LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SER
我在这里不合时宜,所以如果我没有正确/清楚地问这个问题,请原谅我。 我有一张用户表,每个用户都有经纬度。 我收到一个联邦机构的查询,它提供了这样的多边形或圆形: 38.47,-120.14 38.34
我刚刚开始使用 python 的 BeautifulSoup 包进行抓取。在我的代码中,我得到以下汤对象 >>> soupObj [u'$(function(){SEAT.PG.initDialog(
目前我想通过JDBC将我的GPS经纬度发送到MYSQL。为了检索 GPS 纬度,我使用了下面的代码,并且在 GPSTracker 类中有 GPS 跟踪器代码。这将在任何时候按下按钮来 toast 纬度
我想根据输入的源地址和目标地址画一条路线。我需要根据地址获取纬度/日志才能在 android 中绘制 map 。那么我如何根据输入的地址获取纬度/日志。 Geocoder geoCoder = ne
如何在 android map 上显示我从服务器收到的纬度和经度。我实现了 google map V2 但不知道如何在 map 上显示 gps 坐标。经过大量研究,我来到这里,但无法找到一个合理的解决
我的 Controller 中有以下代码。 .controller('MapCtrl', ['$scope', function initialize() {
我也四处搜寻,但没有发现任何真正有帮助的东西。情况如下: 假设我对城市和天气预报有一个简单的关系。我们可以与纬度和经度联系起来,因此我们可以得到以下结果: 城市表: cityId | name
我是一名优秀的程序员,十分优秀!