Android Broadcast Gps Turned On Update Location
Well even having a lot of reading here, i can't figure out the issue. It looks like i never get gps turned on event. After some checking in debug, the flag isGps is correct. But as
Solution 1:
since you receive the event, that means it has nothing to do with the device itself, and looks like it's in your update location, method in my case I'm using 'OnSuccessListener' not 'OnCompleteListener', I don't know if that would be an issue or not, but anyhow that's how I update the location at my side:
/**
* To get the current MapLocation and add marker at that location
*/
@SuppressLint("MissingPermission")
private void setCurrentLocation() {
try {
FusedLocationProviderClient locationClient = new FusedLocationProviderClient(getActivity());
if (checkLocationPermissions()) {
Task<Location> currentLocationTask = locationClient.getLastLocation(); // already checked
currentLocationTask.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
try {
// Now, add the required Marker
addMarker(new LatLng(location.getLatitude(), location.getLongitude()));
} catch (NullPointerException npe) {
npe.printStackTrace();
Toast.makeText(getActivity(), getResources().getString(R.string.cannot_get_location), Toast.LENGTH_SHORT).show();
}
}
});
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Adding a Marker at the Map
*
* @param point the point contains the latitude and longitude to add the marker at
*/
private void addMarker(LatLng point) {
try {
marker.remove();
} catch (NullPointerException ex) {
ex.printStackTrace();
}
MarkerOptions markerOptions = new MarkerOptions().position(
new LatLng(point.latitude, point.longitude)).title(getAddressAtLocation(point));
marker = mMap.addMarker(markerOptions);
currentChosenLocation = point;
}
Post a Comment for "Android Broadcast Gps Turned On Update Location"