在没有目的地的Google地图上x公里后获取纬度经度? [英] Get Latitude Longitude after x kilometer on Google Map without destination?

查看:142
本文介绍了在没有目的地的Google地图上x公里后获取纬度经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Android 应用程序,该应用程序需要在X公里以后找到同一路线上的坐标。 我有两个坐标 x1,y1 & x2,y2 在路上。现在,我的要求是在大约3公里后找到坐标 x3,y3 (即,在 x2,y2 之后的坐标不是之间 x1,y1 & x2,y2 )。
$如果您知道 您可以计算出目的地坐标。



>示例代码:

  private LatLng getDestinationPoint(LatLng source,double brng,double dist){
dist = dist / 6371;
brng = Math.toRadians(brng);

double lat1 = Math.toRadians(source.latitude),lon1 = Math.toRadians(source.longitude);
double lat2 = Math.asin(Math.sin(lat1)* Math.cos(dist)+
Math.cos(lat1)* Math.sin(dist)* Math.cos(brng)) ;
double lon2 = lon1 + Math.atan2(Math.sin(brng)* Math.sin(dist)*
Math.cos(lat1),
Math.cos(dist) - Math .sin(lat1)*
Math.sin(lat2));
if(Double.isNaN(lat2)|| Double.isNaN(lon2)){
return null;
}
返回新的LatLng(Math.toDegrees(lat2),Math.toDegrees(lon2));

$ / code>

示例用法:

  double radiusInKM = 10.0; 
双轴承= 90;
LatLng destinationPoint = getDestinationPoint(new LatLng((25.48,-71.26),bearing,radiusInKM);

或者您可以在pointA和pointB之间使用标题,而不是承载:

  LatLng destinationPoint = getDestinationPoint(new LatLng(37.4038194 ,-122.081267),SphericalUtil.computeHeading(新LatLng(37.7577,-122.4376),新LatLng(37.4038194,-122.081267)),radiusInKM); 



SphericalUtil.computeHeading(p1,p2); 方法来自 Android谷歌地图实用工具库



这是基于这个Stackoverflow答案



如果你想在同一条路上的点,您可以结算这个PHP答案


I am creating an Android app which requires finding a coordinate on the same route after X kilometers.

I have two coordinates x1,y1 & x2,y2 on a road. Now, my requirement is to find coordinate x3,y3 after some 3 kilometers (i.e., coordinate after x2,y2 not between x1,y1 & x2,y2) on the same road.

How can this be achieved ?

解决方案

If you know the bearing, you can calculate the destination coordinate.

Sample Code:

private LatLng getDestinationPoint(LatLng source, double brng, double dist) {
        dist = dist / 6371;
        brng = Math.toRadians(brng);

        double lat1 = Math.toRadians(source.latitude), lon1 = Math.toRadians(source.longitude);
        double lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) +
                                Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
        double lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) *
                                        Math.cos(lat1),
                                        Math.cos(dist) - Math.sin(lat1) *
                                        Math.sin(lat2));
        if (Double.isNaN(lat2) || Double.isNaN(lon2)) {
            return null;
        }
        return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2));
    }

Sample usage:

   double radiusInKM = 10.0;
   double bearing = 90;
   LatLng destinationPoint = getDestinationPoint(new LatLng((25.48, -71.26), bearing, radiusInKM);

Or you can use heading between your pointA and pointB instead of bearing:

LatLng destinationPoint = getDestinationPoint(new LatLng(37.4038194,-122.081267), SphericalUtil.computeHeading(new LatLng(37.7577,-122.4376), new LatLng(37.4038194,-122.081267)), radiusInKM);

The SphericalUtil.computeHeading(p1, p2); method is from the Android Google Maps Utility library.

This is based on the Javascript method from this Stackoverflow answer.

If you want the point on same road, you might checkout this PHP answer.

这篇关于在没有目的地的Google地图上x公里后获取纬度经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆