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

时间:2022-06-20 15:40:24

I have to store longitude and latitude of all cities of a country in android application

我必须在android应用程序中存储一个国家的所有城市的经度和纬度

when user will select a city i have to return the longitude and latitude of selected city.

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

what will be the most efficient way to do this?

什么是最有效的方法呢?

or is there any resources where i enter a country and it will show all cities with their longitude and latitude..?

或者我进入一个国家是否有任何资源,它将显示所有城市的经度和纬度..?

1 个解决方案

#1


0  

You can use Google Geocoding API : https://developers.google.com/maps/documentation/geocoding/

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

For example : https://maps.googleapis.com/maps/api/geocode/json?address=Berlin&sensor=true And parse output using GSON

例如: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"
}

#1


0  

You can use Google Geocoding API : https://developers.google.com/maps/documentation/geocoding/

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

For example : https://maps.googleapis.com/maps/api/geocode/json?address=Berlin&sensor=true And parse output using GSON

例如: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"
}