我正在尝试创建一个应用程序,该应用程序允许我在使用OSMDROID生成的地图上查看各种事件,第一次访问该地图时,我会很快收到GPS位置,但是在切换到另一侧的选项后我实施的导航抽屉,返回到地图,我注意到我从GPS那里获得的位置非常缓慢,花费了超过15秒的时间
我尝试使用以下命令重置A-GPS数据:
locationManager.sendExtraCommand ("gps," delete_aiding_data ", new Bundle ())
但是我还没有看到任何改进,我也曾尝试对onPause,onResume函数进行各种修改,我认为这是真正的问题,但没有成功。我拥有GPS和应用程序中存档的所有权限
public class MapFragment extends Fragment implements LocationListener{
static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
private MapView map;
private MyLocationNewOverlay mLocationOverlay = null;
private CompassOverlay mCompassOverlay = null;
private IMapController mapController = null;
private LocationManager locationManager = null;
private Location posizioneIniziale = null;
private MapFragmentListener listener;
ArrayList<Segnalazione> listReport;
@Override
public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_map, container, false);
map = (MapView) v.findViewById(R.id.map);
return v;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Context ctx = getActivity().getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Log.v(TAG, "Permission is revoked");
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
} else {
ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
}
}
map.setTileSource(TileSourceFactory.MAPNIK);
configMap(ctx);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof MapFragmentListener) {
listener = (MapFragmentListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement MapFragmentListener");
}
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
private void configMap(Context ctx) {
map.setDestroyMode(false);
map.setMultiTouchControls(true);
map.setMinZoomLevel(17.0);
map.setMaxZoomLevel(20.0);
GpsMyLocationProvider provider = new GpsMyLocationProvider(ctx);
provider.addLocationSource(LocationManager.PASSIVE_PROVIDER);
provider.setLocationUpdateMinDistance(0);
provider.setLocationUpdateMinTime(0);
locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE);
locationManager.sendExtraCommand("gps", "delete_aiding_data", new Bundle());
mapController = map.getController();
mLocationOverlay = new MyLocationNewOverlay(provider, map);
mLocationOverlay.setDrawAccuracyEnabled(true);
mLocationOverlay.enableMyLocation();
mLocationOverlay.enableFollowLocation;
Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mapController.setZoom(17.0);
mCompassOverlay = new CompassOverlay(ctx, new InternalCompassOrientationProvider(ctx), map);
mCompassOverlay.enableCompass();
map.getOverlays().add(this.mCompassOverlay);
map.getOverlays().add(this.mLocationOverlay);
}
public void onResume(){
super.onResume();
Manager.getDefaultSharedPreferences(this);
Log.d("RESUME","SONOINRESUME");
map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
}
public void onPause(){
super.onPause();
Log.d("PAUSA","SONOINPAUSA");
locationManager.removeUpdates(this);
}
@Override
public void onLocationChanged(Location location) {
if(this.posizioneIniziale == null ){
posizioneIniziale = location;
listReport = getReportForMap(location.getLatitude(), location.getLongitude());
for (Segnalazione obj : listReport) {
getMarkerFromServer(obj);
}
}
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
}
}