我正在开发一个 android 应用程序,它在地图中显示用户的当前位置。
几个小时后,我发现了错误,locationManager 没有实现位置。
我将代码相对于 locationManager:
mapa = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapaTapas)).getMap();
String serviceString = Context.LOCATION_SERVICE;
LocationManager locationManager = (LocationManager)getSystemService (serviceString);
String proovedor1 = LocationManager.GPS_PROVIDER;
locationManager.getLastKnownLocation(proovedor1);
String proovedor2 = LocationManager.NETWORK_PROVIDER;
locationManager.getLastKnownLocation(proovedor2);
locationManager.requestLocationUpdates(proovedor1, 5000, 5, new LocationListener()
{
@Override
public void onStatusChanged(String arg0, int arg1,Bundle arg2) { }
@Override
public void onProviderEnabled(String arg0) {}
@Override
public void onProviderDisabled(String arg0) {}
@Override
public void onLocationChanged(Location Location)
{
location=Location;
}
});
locationManager.requestLocationUpdates(proovedor2, 5000, 5, new LocationListener()
{
@Override
public void onStatusChanged(String arg0, int arg1,Bundle arg2) { }
@Override
public void onProviderEnabled(String arg0) {}
@Override
public void onProviderDisabled(String arg0) {}
@Override
public void onLocationChanged(Location Location)
{
location=Location;
}
});
location = locationManager.getLastKnownLocation(towers);
if(location != null){
glat = location.getLatitude();
glon = location.getLongitude();
Log.i("location", "latitud: "+glat);
Log.i("location", "latitud: "+glon);
}
cp = new CameraPosition.Builder()
.target(new LatLng(glat, glon))
.zoom(15)
.build();
mapa.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
我需要将位置的当前值保存在 glat 和 glon 中,如果它可能实现一些方法来自动刷新它