1

我向用户提供在某个特定位置创建事件,我用它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";
4

1 回答 1

1

当您仅保存“纽约”搜索的结果时,请务必同时保存纬度/经度范围。

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

边界在 JSON 中 results->geometry->bounds 下

{
   "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"
}

现在,当您想查看“纽约中央公园”是否在“纽约”内时,请简单检查一下中央公园的纬度/经度是否大于西南边界,但小于东北边界。

于 2015-01-16T23:25:29.780 回答