this question might be duplicate,but not getting satisfied answer so here i am throwing my issue.i am trying to fetch current location latitude and longitude using geocoder,before 2days i was able to get latitude and longitude but today getting exception:java.io.IOException: Service not Available
here is the way i am trying to get latitude and longitude
//**current latitude and longitude
try{
lm = (LocationManager) RestaurantDetail.this.getSystemService(Context.LOCATION_SERVICE);
criteria = new Criteria();
bestProvider = lm.getBestProvider(criteria, false);
location = lm.getLastKnownLocation(bestProvider);
}
catch(Exception e){
Log.e("Finding Current Location:",e.toString());
}
if (location == null){
Toast.makeText(RestaurantDetail.this,"Location Not found",Toast.LENGTH_LONG).show();
}else{
try {
geocoder = new Geocoder(RestaurantDetail.this);
user = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
lat=(double)user.get(0).getLatitude();
lng=(double)user.get(0).getLongitude();
lat1=lat;
long1=lng;
Log.e("Latitude:","Current:"+lat1+""+long1+"\n"+"add"+lat2+""+long2);
try{
float results[] = new float[3];
Location.distanceBetween(lat1,long1,lat2,long2, results);
float distance = results[0];
distance=(float) ((distance)*0.000621371);
Tv_restorentdetail_disData.setText(""+distance+"miles");
}catch(Exception e){
Log.e("Counting Distance Exception:",e.toString());
}
}catch (Exception e) {
e.printStackTrace();
Tv_restorentdetail_disData.setText("Service Not Available");
}
my project version is 4.0 with google api and i am testing my project in Samsung tab having android version>4.0 here is a list of permission i have given to manifest file
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
any help or suggestion will be appreciated thanks any way!