English 中文(简体)
如何检查某一个饱和值是否在任何长度范围内?
原标题:How to check if a given longitude value is within any longitude range?

好的。这可能更像是一个数学问题,但我还是试一下。

我有一个经度值,假设为X。我想知道X是否介于任何两个经度值之间。

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

但是,我该如何实际计算呢?

最佳回答
// check if x is between min and max, inclusively
if ( x >= minLongitude && x <= maxLongitude ) 
   return true;
问题回答
/*
 * 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);
}




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签