【发布时间】:2014-09-18 06:42:42
【问题描述】:
我的
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
返回 true 但在位置改变时永远不会被调用。我的 wifi 已打开,GPS 卫星和 wifi 以及网络位置已打开我无法解释为什么它没有被调用。我在下面附上了所需的代码。
try
{
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
gps_enabled=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
network_enabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(!gps_enabled && !network_enabled)
Toast.makeText(MainActivity.this, "Error Getting Your Location", Toast.LENGTH_LONG).show();
else
{
if(network_enabled)
{
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
Toast.makeText(MainActivity.this, "network_enabled", Toast.LENGTH_LONG).show();
}
if(gps_enabled)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
Toast.makeText(MainActivity.this, "gps_enabled", Toast.LENGTH_LONG).show();
}
}
}
catch(Exception ex){}
@Override
public void onLocationChanged(Location location) {
Toast.makeText(MainActivity.this, "onLocationChanged", Toast.LENGTH_LONG).show();
this.lat = location.getLatitude();
this.lon = location.getLongitude();
(new CityList()).execute();
}
这里的 toast gps_enabled 但 onLocationChanged 从未出现。任何人请帮我纠正这些事情。
【问题讨论】:
-
在
onLocationChanged(....)之前添加@Override -
@GG 我看不到的地方..首先正确发布您的代码...
-
它在我的实际代码中。我这里没有贴。但现在我进行编辑。请参考
标签: android location locationmanager