在android中存储经度和纬度数据

时间:2014-03-11 09:32:42

标签: android database latitude-longitude

我必须在Android应用程序中存储一个国家的经度和纬度

当用户选择城市时,我必须返回所选城市的经度和纬度。

最有效的方法是什么?

或是否有我进入某个国家的资源,它会显示所有城市的经度和纬度..?

1 个答案:

答案 0 :(得分:0)

您可以使用Google地理编码API:https://developers.google.com/maps/documentation/geocoding/

例如: https://maps.googleapis.com/maps/api/geocode/json?address=Berlin&sensor=true 并使用GSON解析输出

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Berlin",
               "short_name" : "Berlin",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Berlin",
               "short_name" : "Berlin",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Niemcy",
               "short_name" : "DE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Berlin, Niemcy",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 52.6754542,
                  "lng" : 13.7611176
               },
               "southwest" : {
                  "lat" : 52.33962959999999,
                  "lng" : 13.0911663
               }
            },
            "location" : {
               "lat" : 52.52000659999999,
               "lng" : 13.404954
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 52.6754542,
                  "lng" : 13.7611176
               },
               "southwest" : {
                  "lat" : 52.33962959999999,
                  "lng" : 13.0911663
               }
            }
         },
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}