in reply to Determine lat/lon of geo location at given distance from other location
#!/usr/bin/env perl use strict; use warnings; use Geo::Ellipsoid; print "\nUsing Geo::Ellipsoid\n"; my $gel = Geo::Ellipsoid->new( ellipsoid => 'WGS84', units => 'degrees', distance_units => 'meter', longitude => 0, bearing => 0, ); my @curlatlon1 = (37.889086, 41.129166); my @curlatlon2 = (39.668930, 66.993292); # displacement from 1 to 2 my ($x,$y) = $gel->displacement(@curlatlon1, @curlatlon2); print "displacement from @curlatlon1 to @curlatlon2 = ($x,$y)\n"; my @newlatlon = $gel->location(@curlatlon1, $x, $y); print "moving from @curlatlon1 by ($x,$y) gets me to @newlatlon (corre +ct is @curlatlon2)\n"; print "dist: ".sqrt($x*$x+$y*$y) .", bearing: ".180*atan2($y,$x)/3.14." degrees\n"; # from 2 to 1 ($x,$y) = $gel->displacement(@curlatlon2, @curlatlon1); print "displacement from @curlatlon2 to @curlatlon1 = ($x,$y)\n"; @newlatlon = $gel->location(@curlatlon2, $x, $y); print "moving from @curlatlon2 by ($x,$y) gets me to @newlatlon (corre +ct is @curlatlon1)\n"; print "dist: ".sqrt($x*$x+$y*$y) .", bearing: ".180*atan2($y,$x)/3.14." degrees\n"; use Geo::Calc; print "\nUsing Geo::Calc\n"; my $cur1 = Geo::Calc->new(lat=>$curlatlon1[0], lon=>$curlatlon1[1]); my $bear = $cur1->bearing_to({lat=>$curlatlon2[0], lon=>$curlatlon2[1] +}); my $dist = $cur1->distance_to({lat=>$curlatlon2[0], lon=>$curlatlon2[1 +]}); my $newlatlon = $cur1->destination_point($bear, $dist); print "from (" .$cur1->get_lat().",".$cur1->get_lon() .") moving by $dist m and $bear degrees got me to (" .$newlatlon->{'lat'}.",".$newlatlon->{'lon'} .")\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determine lat/lon of geo location at given distance from other location
by Aldebaran (Curate) on Jul 01, 2019 at 18:30 UTC |