如何用坐标移动标记100米 [英] How to move a marker 100 meters with coordinates
问题描述
我有2个坐标。坐标1是一个'人'。坐标2是目的地。
我如何将坐标1移近100米以接近坐标2?
将被用于cron作业,所以只包括php和mysql。
例如:
人为:51.26667,3.45417
目的地是:51.575001,4.83889
我如何计算Person的新坐标更接近100米? 使用Haversine来计算以米为单位的两点之间的差异;然后按比例调整人物坐标的值。
$ radius = 6378100; //以米为单位的地球半径
$ latDist = $ lat - $ lat2;
$ lngDist = $ lng - $ lng2;
$ latDistRad = deg2rad($ latDist);
$ lngDistRad = deg2rad($ lngDist);
$ sinLatD = sin($ latDistRad);
$ sinLngD = sin($ lngDistRad);
$ cosLat1 = cos(deg2rad($ lat));
$ cosLat2 = cos(deg2rad($ lat2));
$ a =($ sinLatD / 2)*($ sinLatD / 2)+ $ cosLat1 * $ cosLat2 *($ sinLngD / 2)*($ sinLngD / 2);
if($ a< 0)$ a = -1 * $ a;
$ c = 2 * atan2(sqrt($ a),sqrt(1- $ a));
$ distance = $ radius * $ c;
提供以下值:
$ lat = 51.26667; //比利时阿登堡南部
$ lng = 3.45417;
$ lat2 = 51.575001; //到荷兰布雷达东部
$ lng2 = 4.83889;
结果为102059.82251083米,102.06公里b
$ b
要调整的比率为100 / 102059.82251083 = 0.0009798174985988102859004569070625
$ $ $ $ $ $ $ $ $ $ $ $ $($ lat2 $ lat)* $比例);
$ newLng = $ lng +(($ lng2 - $ lng)* $ ratio);
给出新的纬度51.266972108109和经度3.4555267728867
I have 2 coordinates. Coordinate 1 is a 'person'. Coordinate 2 is a destination.
How do I move coordinate 1 100 meters closer to coordinate 2?
This would be used in a cron job, so only php and mysql included.
For example:
Person is at: 51.26667, 3.45417
Destination is: 51.575001, 4.83889
How would i calculate the new coordinates for Person to be 100 meters closer?
Use Haversine to calculate the difference between the two points in metres; then adjust the value of the person coordinates proportionally.
$radius = 6378100; // radius of earth in meters
$latDist = $lat - $lat2;
$lngDist = $lng - $lng2;
$latDistRad = deg2rad($latDist);
$lngDistRad = deg2rad($lngDist);
$sinLatD = sin($latDistRad);
$sinLngD = sin($lngDistRad);
$cosLat1 = cos(deg2rad($lat));
$cosLat2 = cos(deg2rad($lat2));
$a = ($sinLatD/2)*($sinLatD/2) + $cosLat1*$cosLat2*($sinLngD/2)*($sinLngD/2);
if($a<0) $a = -1*$a;
$c = 2*atan2(sqrt($a), sqrt(1-$a));
$distance = $radius*$c;
Feeding your values of:
$lat = 51.26667; // Just South of Aardenburg in Belgium
$lng = 3.45417;
$lat2 = 51.575001; // To the East of Breda in Holland
$lng2 = 4.83889;
gives a result of 102059.82251083 metres, 102.06 kilometers
The ratio to adjust by is 100 / 102059.82251083 = 0.0009798174985988102859004569070625
$newLat = $lat + (($lat2 - $lat) * $ratio);
$newLng = $lng + (($lng2 - $lng) * $ratio);
Gives a new latitude of 51.266972108109 and longitude of 3.4555267728867
这篇关于如何用坐标移动标记100米的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!