我正在尝试使用服务器端的经度和纬度来获取位置。
https://maps.googleapis.com/maps/api/geocode/json?latlng=28.520506,77.20151&key=AIzaSyCmh3btBq1PK-gx98R_akhab9xzRFjfAzc
如下所示:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Mehrauli - Badarpur Road",
"short_name" : "Mehrauli - Badarpur Rd",
"types" : [ "route" ]
},
{
"long_name" : "Block A",
"short_name" : "Block A",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "DDA Flats",
"short_name" : "DDA Flats",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Saket",
"short_name" : "Saket",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "110044",
"short_name" : "110044",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Mehrauli - Badarpur Road, Block A, DDA Flats, Saket, New Delhi, Delhi 110044, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.5207757,
"lng" : 77.20210809999999
},
"southwest" : {
"lat" : 28.5206053,
"lng" : 77.2013937
}
},
"location" : {
"lat" : 28.5206905,
"lng" : 77.20175089999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5220394802915,
"lng" : 77.2030998802915
},
"southwest" : {
"lat" : 28.5193415197085,
"lng" : 77.2004019197085
}
}
},
"place_id" : "ChIJBVdwbfvhDDkRPQndknfs_uY",
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "Saket",
"short_name" : "Saket Metro Station",
"types" : [ "subway_station", "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "Mehrauli - Badarpur Road",
"short_name" : "Mehrauli - Badarpur Rd",
"types" : [ "route" ]
},
{
"long_name" : "Saiyad ul Ajaib",
"short_name" : "Saiyad ul Ajaib",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Saiyad Ul Ajaib Village",
"short_name" : "Saiyad Ul Ajaib Village",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Saket",
"short_name" : "Saket",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "110030",
"short_name" : "110030",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Saket, Mehrauli - Badarpur Road, Saiyad ul Ajaib, Saiyad Ul Ajaib Village, Saket, New Delhi, Delhi 110030, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.5205491,
"lng" : 77.20161709999999
},
"southwest" : {
"lat" : 28.5204151,
"lng" : 77.20142389999999
}
},
"location" : {
"lat" : 28.5205063,
"lng" : 77.2015098
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5218310802915,
"lng" : 77.20286948029151
},
"southwest" : {
"lat" : 28.5191331197085,
"lng" : 77.20017151970849
}
}
},
"place_id" : "ChIJtRwRbfvhDDkRNdb4NK6iicg",
"types" : [ "subway_station", "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Saket Metro Station",
"short_name" : "Saket Metro Station",
"types" : [ "point_of_interest", "establishment" ]
},
{
"long_name" : "Mehrauli - Badarpur Road",
"short_name" : "Mehrauli - Badarpur Rd",
"types" : [ "route" ]
},
{
"long_name" : "Saiyad ul Ajaib",
"short_name" : "Saiyad ul Ajaib",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Saiyad Ul Ajaib Village",
"short_name" : "Saiyad Ul Ajaib Village",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Sainik Farm",
"short_name" : "Sainik Farm",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "110017",
"short_name" : "110017",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Saket Metro Station, Mehrauli - Badarpur Road, Saiyad ul Ajaib, Saiyad Ul Ajaib Village, Sainik Farm, New Delhi, Delhi 110017, India",
"geometry" : {
"location" : {
"lat" : 28.520528,
"lng" : 77.201505
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5218769802915,
"lng" : 77.20285398029151
},
"southwest" : {
"lat" : 28.5191790197085,
"lng" : 77.2001560197085
}
}
},
"place_id" : "ChIJBzy8HfvhDDkRa124f53C6hI",
"types" : [ "transit_station", "point_of_interest", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Saiyad Ul Ajaib Village",
"short_name" : "Saiyad Ul Ajaib Village",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Sainik Farm",
"short_name" : "Sainik Farm",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Saiyad Ul Ajaib Village, Sainik Farm, New Delhi, Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.5208191,
"lng" : 77.20672110000001
},
"southwest" : {
"lat" : 28.5159519,
"lng" : 77.1994859
}
},
"location" : {
"lat" : 28.5194062,
"lng" : 77.2024306
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5208191,
"lng" : 77.20672110000001
},
"southwest" : {
"lat" : 28.5159519,
"lng" : 77.1994859
}
}
},
"place_id" : "ChIJu3kI1uThDDkR7iU8hablnbU",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Saiyad ul Ajaib",
"short_name" : "Saiyad ul Ajaib",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Block E",
"short_name" : "Block E",
"types" : [ "sublocality_level_3", "sublocality", "political" ]
},
{
"long_name" : "Saiyad Ul Ajaib Village",
"short_name" : "Saiyad Ul Ajaib Village",
"types" : [ "sublocality_level_2", "sublocality", "political" ]
},
{
"long_name" : "Sainik Farm",
"short_name" : "Sainik Farm",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Saiyad ul Ajaib, Block E, Saiyad Ul Ajaib Village, Sainik Farm, New Delhi, Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.520712,
"lng" : 77.2065688
},
"southwest" : {
"lat" : 28.5112375,
"lng" : 77.18968389999999
}
},
"location" : {
"lat" : 28.517186,
"lng" : 77.20171189999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.520712,
"lng" : 77.2065688
},
"southwest" : {
"lat" : 28.5112375,
"lng" : 77.18968389999999
}
}
},
"place_id" : "ChIJnTMcyuThDDkRTUiS4Zu2qW4",
"types" : [ "neighborhood", "political" ]
},
{
"address_components" : [
{
"long_name" : "Sainik Farm",
"short_name" : "Sainik Farm",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Sainik Farm, New Delhi, Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.5234901,
"lng" : 77.22944389999999
},
"southwest" : {
"lat" : 28.485256,
"lng" : 77.18350099999999
}
},
"location" : {
"lat" : 28.5068824,
"lng" : 77.211229
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5234901,
"lng" : 77.22944389999999
},
"southwest" : {
"lat" : 28.485256,
"lng" : 77.18350099999999
}
}
},
"place_id" : "ChIJZ2itOb_hDDkRTq6aivCYp_Q",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New Delhi, Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.889816,
"lng" : 77.3418147
},
"southwest" : {
"lat" : 28.4010669,
"lng" : 76.8396999
}
},
"location" : {
"lat" : 28.6139391,
"lng" : 77.2090212
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.889816,
"lng" : 77.3418147
},
"southwest" : {
"lat" : 28.4010669,
"lng" : 76.8396999
}
}
},
"place_id" : "ChIJLbZ-NFv9DDkRzk0gTkm3wlI",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "110030",
"short_name" : "110030",
"types" : [ "postal_code" ]
},
{
"long_name" : "New Delhi",
"short_name" : "New Delhi",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New Delhi, Delhi 110030, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.5347099,
"lng" : 77.20646719999999
},
"southwest" : {
"lat" : 28.4761952,
"lng" : 77.1228993
}
},
"location" : {
"lat" : 28.4956835,
"lng" : 77.1664945
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.5347099,
"lng" : 77.20646719999999
},
"southwest" : {
"lat" : 28.4761952,
"lng" : 77.1228993
}
}
},
"place_id" : "ChIJYaOVHDceDTkRyvLz3dSSVIk",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "South Delhi",
"short_name" : "South Delhi",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "South Delhi, Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.6118999,
"lng" : 77.34496009999999
},
"southwest" : {
"lat" : 28.4041,
"lng" : 77.11156
}
},
"location" : {
"lat" : 28.5086497,
"lng" : 77.2175223
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.6118999,
"lng" : 77.34496009999999
},
"southwest" : {
"lat" : 28.4041,
"lng" : 77.11156
}
}
},
"place_id" : "ChIJqX7ja73hDDkRRA9T2LXUAJg",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "Delhi",
"short_name" : "DL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Delhi, India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 28.881338,
"lng" : 77.34845780000001
},
"southwest" : {
"lat" : 28.412593,
"lng" : 76.83806899999999
}
},
"location" : {
"lat" : 28.7040592,
"lng" : 77.10249019999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 28.881338,
"lng" : 77.34845780000001
},
"southwest" : {
"lat" : 28.412593,
"lng" : 76.83806899999999
}
}
},
"place_id" : "ChIJLbZ-NFv9DDkRQJY4FbcFcgM",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"address_components" : [
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "India",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 35.5087008,
"lng" : 97.395561
},
"southwest" : {
"lat" : 6.7535159,
"lng" : 68.162386
}
},
"location" : {
"lat" : 20.593684,
"lng" : 78.96288
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 35.5087008,
"lng" : 97.395561
},
"southwest" : {
"lat" : 6.7535159,
"lng" : 68.16288519999999
}
}
},
"place_id" : "ChIJkbeSa_BfYzARphNChaFPjNc",
"types" : [ "country", "political" ]
}
],
"status" : "OK"
}

此响应包含纬度和经度指定位置附近的多个地址。我有兴趣从这个回复中提取地点。
例如,在上述查询的情况下,位置为 Saket ,位于印度德里。
如果我尝试根据地址类型的过滤来限制结果,它只会限制响应中的地址数量,但仍会返回多个地址。
如何提取精确或近似位置?
任何帮助表示感谢。
答案 0 :(得分:1)
地理编码不是一对一的;单个lat / lon对应多个事物。你能做的最好的事情就是将它们排在重要位置(谷歌已经这样做了)并挑选最重要的一个。您还可以根据自己的参数对其进行排序,例如与查询点的距离。但是没有办法保证一个结果。