如何检查特定地址的经纬度是否属于城市的纬度和经度?

How to check if latitude and longitude of a specific address belongs to lat and long of a city?

我建议用户在某个特定的地方创建一个活动,我使用 Google places API 来自动完成地址。因此,当用户键入 "New Yor" 时,它可能会向他提供 "New York, Central Park"。如果他选择那个,整个地址被保存在数据库中+地址的纬度和经度。

现在问题来了,当另一个用户想要查看来自 New York 的所有事件时。

由于我使用的服务不支持通配符搜索,我正在寻找一种方法来查看 New York 纬度和经度是否包含 New York, Central Park 纬度和经度。

有什么想法吗?

一些代码:

uri = "https://www.maps.google.com/maps/api/geocode/json?address=" +
                URLEncoder.encode(params[0].toString(), "UTF-8") +  
"&sensor=false";

当您仅保存 "New York" 搜索的结果时,请务必同时保存 latitude/longitude 范围。

http://maps.google.com/maps/api/geocode/json?address=new%20york

边界在results->geometry->bounds

下的JSON
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "New York, NY, USA",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 40.91525559999999,
                  "lng" : -73.70027209999999
               },
               "southwest" : {
                  "lat" : 40.4913686,
                  "lng" : -74.25908989999999
               }
            },
            "location" : {
               "lat" : 40.7127837,
               "lng" : -74.0059413
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.91525559999999,
                  "lng" : -73.70027209999999
               },
               "southwest" : {
                  "lat" : 40.4913686,
                  "lng" : -74.25908989999999
               }
            }
         },
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}

现在,如果您想查看 "New York Central Park" 是否在 "New York" 内,请简单检查一下中央公园的 lat/long 是否大于西南边界,但小于西南边界东北边界.