检查一个城市是否位于东北纬度/液化天然气和西南纬度/液化天然气的国家/地区



我正在开发一个使用谷歌API的PHP应用程序,我想检查一个城市是否在一个国家。

例如:巴黎在法国吗?

法国几何边界:

 "northeast" : {
                  "lat" : 51.089166,
                  "lng" : 9.560067799999999
               },
 "southwest" : {
                  "lat" : 41.3423276,
                  "lng" : -5.141227900000001
               }

巴黎几何边界:

 "northeast" : {
              "lat" : 48.9021449,
              "lng" : 2.4699208
           },
 "southwest" : {
              "lat" : 48.815573,
              "lng" : 2.224199
           }

谢谢。

有趣的问题。看看这个我做了一个例子:

function inRange($value, $max, $min) {
   return $value >= $min && $value <= $max;
}
$city_coords_northeast = // put your northeast city coords here(array)
$city_coords_southwest = // put your southwest city coords here(array)
$country_coords_northeast = // put your northeast country coords here(array)
$country_coords_southwest = // put your southwest country coords here(array)
if( inRange($city_coords_northeast['lat'], $country_coords_northeast['lat'], $country_coords_southwest['lat']) && 
    inRange($city_coords_northeast['long'], $country_coords_northeast['long'], $country_coords_southwest['long']) &&
    inRange($country_coords_southwest['lat'], $city_coords_northeast['lat'], $city_coords_southwest['lat']) &&
    inRange($country_coords_southwest['long'], $city_coords_northeast['long'], $city_coords_southwest['long']) ) {
   echo 'Paris is in France!';
}

PS:我不认为这很快,但它可以发挥作用。

相关内容

最新更新