1

我想在两个城市之间的墨卡托地图上画一条折线。例如起点:

 Location berlin = new Location(52.517, 13.40);
 Location tokio = new Location(35.70,139.767);

它应该看起来像一条航线。

所以我的计划是遍历两个城市之间的所有经度值并计算相应的纬度值:

LocationCollection locationCollection = new LocationCollection();

Location next = new Location(berlin.Latitude,berlin.Longitude); //startpunkt
for (double x = berlin.Longitude+1; x < tokio.Longitude; x++) {
  locationCollection.Add(next);
  next = new Location(???, x);
}

问题是如何计算折线的每个经度值的纬度?谢谢!

4

1 回答 1

0

这个链接

这是 C 中的一个实现。

#define PI 3.14159265358979323846
double degrees_radians(double d) { return d * PI / 180.0; }
double radians_degrees(double r) { return r * 180.0 / PI; }

double latitude(double lat1, double lon1, double lat2, double lon2, double lon)
{
    return atan((sin(lat1)*cos(lat2)*sin(lon-lon2)-sin(lat2)*cos(lat1)*sin(lon-lon1))/(cos(lat1)*cos(lat2)*sin(lon1-lon2)));
}

int main()
{
    // start and end in degrees
    double lat1_d = 52.517;
    double lon1_d = 13.40;
    double lat2_d = 35.70;
    double lon2_d = 139.767;

    // start and end in radians
    double lat1_r = degrees_radians(lat1_d);
    double lon1_r = degrees_radians(lon1_d);
    double lat2_r = degrees_radians(lat2_d);
    double lon2_r = degrees_radians(lon2_d);

    // interpolate latitide at every degree of longitude between 1 and 2
    for (double lon = ceil(lon1_d); lon < lon2_d; lon += 1.0)
    {
        double lat_r = latitude(lat1_r, lon1_r, lat2_r, lon2_r, degrees_radians(lon));
        double lat_d = radians_degrees(lat_r);
        printf("%.3f , %.3f\n", lat_d, lon);
    }

    return 0;
}

在柏林和东京之间的大圆上达到的最大纬度显示为经度 68° 处的 66.183°。

于 2012-11-13T10:54:07.300 回答