开发者

How to move x distance in any direction from geo coordinates?

I'm using Google Places API to get a list of establishment near a geo location, and I'm trying to figure out how to move 1km north and get geo coordinates there and then do another Google API call.

Ideally I'd like to be able to go into any direction for any distance and get the geo coordinates. Where do i start? If this is not possible then please let me know.

I'm not getting anything. Please have a look. How exactly do i use the direction. How do i go north?

$lat = "40.712714";
$lon = "-74.005997";
$direction = "80";
$length="2000";

 move($lon, $lat, $direction, $length);


function move($cx,$cy,$direction,$length){
    $x=$cx*cos($direction*M_PI/180)+$length;
    $y=$cy*sin($direction*M_PI/180)+$length;
    return array($x,$y);
    echo $x;
    echo $y;
    }

EDIT I just tried changing the coordinates number manually and it seems to do what I want. For example I take these coordinates

开发者_C百科

40.717828,-73.998672

and changed the 3rd decimal number. That moved my location north.

40.710828,-73.998672


I have conducted a little investigation. This is the corrected code for this function:

function move($ylat,$xlng,$direction_degree,$length_degree){
    $x=$xlng+$length_degree*cos($direction_degree*M_PI/180);
    $y=$ylat+$length_degree*sin($direction_degree*M_PI/180);
    return array($x,$y);
}

var_dump(move(52.1,11.2,0,1)); //North 1 degree.

However, there are a few minor problems to fix before you can use it as you would like.

  • This function has the distance in degrees, so you need to convert metres to degrees first. Beware that is varies along the latitude.
  • The direction is in degrees, 0 is north, 90 east, 180 south, 270 west.
  • I recommend you orginate from degrees then do metre-conversion lastly. By then you just do distance between old and new coordinates.


Quoting from this wikipedia article GCS Wiki Article:

On the GRS80 or WGS84 spheroid at sea level at the equator, one latitudinal second measures 30.715 metres, one latitudinal minute is 1843 metres and one latitudinal degree is 110.6 kilometres. The circles of longitude, meridians, meet at the geographical poles, with the west-east width of a second naturally decreasing as latitude increases. On the equator at sea level, one longitudinal second measures 30.92 metres, a longitudinal minute is 1855 metres and a longitudinal degree is 111.3 kilometres. At 30° a longitudinal second is 26.76 metres, at Greenwich (51° 28' 38" N) 19.22 metres, and at 60° it is 15.42 metres.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜