a
This commit is contained in:
parent
cad9f466c2
commit
40101ef7d0
@ -1,15 +1,19 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
@ -75,6 +79,8 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
private PermissionsManager permissionsManager;
|
||||
private LocationComponent locationComponent;
|
||||
LocationManager mLocationManager;
|
||||
|
||||
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
@ -190,10 +196,6 @@ public class MapActivity extends BaseActivity
|
||||
// TODO PUT MANUAL CORD
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latLng.getLatitude(),
|
||||
@ -212,18 +214,18 @@ public class MapActivity extends BaseActivity
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e(tag+"POST", String.valueOf(coord));
|
||||
Log.e(tag + "POST", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e(tag+"onError", e.getMessage());
|
||||
Log.e(tag + "onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e(tag+"onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
@ -233,15 +235,6 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Toast.makeText(
|
||||
MapActivity.this,
|
||||
"Manual Locations selected!" + latLng,
|
||||
@ -478,17 +471,18 @@ public class MapActivity extends BaseActivity
|
||||
private void enableLocationPlugin() {
|
||||
// Check if permissions are enabled and if not request
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.trackingGesturesManagement(true)
|
||||
.accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
|
||||
.build();
|
||||
|
||||
// Get an instance of the component
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
|
||||
// TODO mieszko tu jest lepsza lokalizacja
|
||||
// TODO tu jest lepsza lokalizacja(chyba)
|
||||
// locationComponent.getLastKnownLocation();
|
||||
// Log.e(tag + "Last", getLastKnownLocation() + "");
|
||||
//Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
|
||||
|
||||
// Activate with options
|
||||
locationComponent.activateLocationComponent(this, options);
|
||||
@ -530,12 +524,13 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExplanationNeeded(List<String> permissionsToExplain) {
|
||||
Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -547,4 +542,26 @@ public class MapActivity extends BaseActivity
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Location getLastKnownLocation() {
|
||||
mLocationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
|
||||
List<String> providers = mLocationManager.getProviders(true);
|
||||
Location bestLocation = null;
|
||||
for (String provider : providers) {
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
permissionsManager = new PermissionsManager(this);
|
||||
permissionsManager.requestLocationPermissions(this);
|
||||
}
|
||||
Location l = mLocationManager.getLastKnownLocation(provider);
|
||||
if (l == null) {
|
||||
continue;
|
||||
}
|
||||
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
|
||||
// Found best last known location: %s", l);
|
||||
bestLocation = l;
|
||||
}
|
||||
}
|
||||
return bestLocation;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user