查找给定的纬度/经度坐标是否位于正方形/矩形内

问题描述 投票:-2回答:1

我有3组坐标

  1. 协调检查
  2. NorthWest坐标
  3. 东南方坐标

2和3是正方形/矩形的对角线。我必须找到给定的坐标(1)是否位于2和3内。

之前发布了同样的问题,但没有发布答案。 Duplicate Question

java google-maps
1个回答
1
投票

我得到了我正在寻找的解决方案。 Got solution from here

/*
* 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;
}
© www.soinside.com 2019 - 2024. All rights reserved.