In the method getLocation()
the problem is probably here:
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
because getLastKnownLocation
can return null
if the previous location is unknown. So by calling location.getLatitude()
you incur in a NullPointerException
.
To avoid this you can check the returned value for null
like:
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
if(location!=null)
//...etc...