获取国家代码的Android位置
我想根据设备的当前位置获取国家/地区代码。我使用了LocationListener,如下所示:获取国家代码的Android位置,android,location,Android,Location,我想根据设备的当前位置获取国家/地区代码。我使用了LocationListener,如下所示: locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { makeUseOfNewLocation(
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
makeUseOfNewLocation(location);
}
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locationListener);
。。。但返回位置需要很长时间
如何更快地获取国家/地区代码?也许您应该使用? 例如: 国家代码:
Locale.getDefault().getCountry
语言代码:
Locale.getDefault().getLanguage()
希望有帮助。如果您使用GPS提供商,则可能需要等待GPS信号。考虑到您只想确定国家/地区,网络提供商应该提供足够的粒度,并且应该给您更快的响应 您还可以使用最后一个已知位置更快地修复您的位置:
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
请参阅:请提供您迄今为止尝试的代码….locationManager=locationManager getSystemServiceContext.LOCATION\u服务;locationListener=new locationListener{public void onLocationChangedLocation location{makeUseOfNewLocationlocation;}locationManager.requestLocationUpdatesLocationManager.GPS_提供程序,0,0,locationListener;感谢您的回复,但它有一些问题。例如,它返回设备制造商国家/地区代码而不是当前。。。。