如何测试纬度/经度点是否在地图内(不是谷歌地图) [英] How to test if a Latitude/Longitude point is within a Map (not google maps)

查看:235
本文介绍了如何测试纬度/经度点是否在地图内(不是谷歌地图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个类来定义一个由经度和纬度定义的顶部/左边的地图,并且底部/右边也由经度和纬度定义,那么如何测试给定的纬度/经度是否在地图内边界点?
{这不是与谷歌地图有关的问题)。
eg(奥兰多在地图上覆盖Tallhasse到迈阿密)。

If I have a class that defines a map with the top/left defined by a longitude and latitude, and the bottom/right also defined by a longitude and latitude, how can test if a given latitude/longitude is within the map's bounding points? {This is not a question that has to do with Google Maps). eg (is Orlando within a map that covers Tallhasse to Miami).

公共类MapContext {

public class MapContext {

private Location mMapTop = null;
private Location mMapBottom = null;



public MapContext(String topLatitude,String topLongitude, String bottomLatitude, String bottomLongitude) {


    double theTopLat = Location.convert(topLatitude);
    double theTopLong = Location.convert(topLongitude);
    mMapTop = new Location("private");
    mMapTop.setLongitude(theTopLong);
    mMapTop.setLatitude(theTopLat);

    double theBottomLat = Location.convert(bottomLatitude);
    double theBottomLong = Location.convert(bottomLongitude);
    mMapBottom = new Location("private");
    mMapBottom.setLongitude(theBottomLong);
    mMapBottom.setLatitude(theBottomLat);

}
public boolean testIfPointOnMap(Location location){


返回TRUE或FALSE
}
}

} public boolean testIfPointOnMap(Location location) { ? ? return TRUE or FALSE } }

推荐答案

你能检查看看是否lat long是在界限之间?

Can you just check to see if the lat long is between the bounds?

   /*
    * top: north latitude of bounding box.
    * left: left longitude of bounding box (western bound). 
    * bottom: south latitude of the bounding box.
    * right: right longitude of bounding box (eastern bound).
    * latitude: latitude of the point to check.
    * longitude: longitude of the point to check.
    */
    boolean isBounded(double top, double left, 
                      double bottom, double right, 
                      double latitude, double longitude){
            /* Check latitude bounds first. */
            if(top >= latitude && latitude >= bottom){
                    /* If your bounding box doesn't wrap 
                       the date line the value
                       must be between the bounds.
                       If your bounding box does wrap the 
                       date line it only needs to be  
                       higher than the left bound or 
                       lower than the right bound. */
                if(left <= right && left <= longitude && longitude <= right){
                    return true;
                } else if(left > right && (left <= longitude || longitude <= right)) {
                    return true;
                }
            }
            return false;
    }

这篇关于如何测试纬度/经度点是否在地图内(不是谷歌地图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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