1

好的。这可能更像是一个数学问题,但在这里。

我有一个经度值,比如说 X。我想知道 X 是否介于任意两个经度值之间。

例如,如果我的 X 是 145,范围是 [21, -179]。该范围由谷歌地图 API 边界给出,我可以在谷歌地图上看到 X 确实在该范围内。

但是,我该如何计算呢?

4

2 回答 2

1
// check if x is between min and max, inclusively
if ( x >= minLongitude && x <= maxLongitude ) 
   return true;
于 2010-04-09T21:42:49.140 回答
0
/*
 * Return true if and only if the longitude value lng lies in the range [min, max].
 *
 * All input values should be in the range [-180, +180].
 * The test is conducted clockwise.
 */
private boolean isLongitudeInRange(double lng, double min, double max) {

    assert(lng >= -180.0 && lng <= 180.0);
    assert(min >= -180.0 && min <= 180.0);
    assert(max >= -180.0 && max <= 180.0);

    if (lng < min) {
        lng += 360.0;
    }

    if (max < min) {
        max += 360.0;
    }

    return (lng >= min) && (lng <= max);
}
于 2010-08-19T10:38:42.857 回答