问题描述
我正在写一个Android应用程序,它使用定位服务。我想借以了解物质的国家区域,其中用户的位置。我怎样才能做到这一点?
I'm writing an Android app, which uses location services. I want to detrmine the country region, in which the user is located. How can I achieve that ?
推荐答案
您可以做一个使用谷歌地理codeR API的
You can make a use of the Google Geocoder API
所有你需要做的是让合适的查询,例如在请求到谷歌地理codeR提供给用户的经度和纬度的格式(在URL)的位置,然后解析JSON / XML响应。你可以看到,在提供有例子是JSON字符串,它标志着国家:
All you need to do is to make appropriate query, e.g in the request to the Google Geocoder providing the user's location in Latitude and Longitude format (in the url), and then parse the JSON/XML response. You can see that in the example that is provided there is JSON string that signifies the country:
{
"status": "OK",
"results": [ {
"types": [ "street_address" ],
"formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"address_components": [ {
"long_name": "1600",
"short_name": "1600",
"types": [ "street_number" ]
}, {
"long_name": "Amphitheatre Pkwy",
"short_name": "Amphitheatre Pkwy",
"types": [ "route" ]
}, {
"long_name": "Mountain View",
"short_name": "Mountain View",
"types": [ "locality", "political" ]
}, {
"long_name": "California",
"short_name": "CA",
"types": [ "administrative_area_level_1", "political" ]
}, {
"long_name": "United States", // <----- HERE IS THE COUNTRY NAME.
"short_name": "US",
"types": [ "country", "political" ]
}, {
"long_name": "94043",
"short_name": "94043",
"types": [ "postal_code" ]
} ],
"geometry": {
"location": {
"lat": 37.4219720,
"lng": -122.0841430
},
"location_type": "ROOFTOP",
"viewport": {
"southwest": {
"lat": 37.4188244,
"lng": -122.0872906
},
"northeast": {
"lat": 37.4251196,
"lng": -122.0809954
}
}
}
} ]
}
如果我的链接不清或短,你可以阅读更多。或使用从谷歌地图API地理codeR类Android版
If I was unclear or short on the link you can read more. Or use Geocoder class from Google Maps API for android
这篇关于Android的定位服务 - 从用户的当前位置确定国家地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!