dtr32787 2011-09-09 02:47
浏览 74
已采纳

如何从地理坐标向任何方向移动x距离?

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

40.717828,-73.998672

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

40.710828,-73.998672

  • 写回答

2条回答 默认 最新

  • dongtanzhu5417 2011-09-10 14:00
    关注

    So 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 (eg loceo.se/doc/distance)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)