安卓LocationManager.getLastKnownLocation()返回在Android 4.1.1空 [英] Android LocationManager.getLastKnownLocation() returns null on Android 4.1.1
本文介绍了安卓LocationManager.getLastKnownLocation()返回在Android 4.1.1空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的android应用。我陷在问题。
getLastKnownLocation(提供者)
返回空
为Android 4.1.1版本,而其他版本中,它是罚款。供应商已启用,其余的就可以了。我不知道问题出在哪里。这里是code。
LocationManager locationManager =(LocationManager)getSystemService(LOCATION_SERVICE);
标准标准=新标准();
字符串商= locationManager.getBestProvider(标准,真正的);
位置= locationManager.getLastKnownLocation(供应商);
双纬度= location.getLatitude();
双经度= location.getLongitude();
经纬度经纬度=新的经纬度(纬度,经度);
mMap.clear();
的System.out.println(当前位置=+经纬度);
解决方案
试试这个它的工作对我来说...
mGoogleMap.setOnMyLocationButtonClickListener(新OnMyLocationButtonClickListener(){
@覆盖
公共布尔onMyLocationButtonClick()
{
位置myLocation = mGoogleMap.getMyLocation();
onLocationChanged(myLocation);
返回false;
}
});
I am working on android application. I am stuck in problem.
getLastKnownLocation(provider)
returns null
for Android version 4.1.1, while for other versions it is fine. Provider is enabled and the rest is ok. I don't know where is the problem. Here is the code.
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
location = locationManager.getLastKnownLocation(provider);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
mMap.clear();
System.out.println("Current Location = "+latLng);
解决方案
try this its working for me...
mGoogleMap.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick()
{
Location myLocation = mGoogleMap.getMyLocation();
onLocationChanged(myLocation);
return false;
}
});
这篇关于安卓LocationManager.getLastKnownLocation()返回在Android 4.1.1空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文