In my application I want current location. I am getting latitude and longitude succesfully. Now I want to complete address from that lat long. Here is my code:
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
// \n is for new line
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
System.out.println("$$$$$$"+latitude+":::"+longitude);
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
String fullAdd = address+":"+city;
sendSMS(IncomingCallReceiver.phonenumber,fullAdd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
String fullAdd = "Latitude:"+latitude+",Longitude:"+longitude;
sendSMS(IncomingCallReceiver.phonenumber,fullAdd);
}
Now what I want is if suppose I am not get complete address then I want to try 5 more times to get aomplete address and if then also not get location then only I want to send latitude and longitude.
Any suggestion will be appreciated.
Here is my logcat:
04-26 14:54:35.359: W/System.err(11976): java.io.IOException: Unable to parse response from server
04-26 14:54:35.359: W/System.err(11976): at android.location.Geocoder.getFromLocation(Geocoder.java:136)
04-26 14:54:35.359: W/System.err(11976): at com.example.locationtracker.LocationService.getLocation(LocationService.java:88)
04-26 14:54:35.359: W/System.err(11976): at com.example.locationtracker.LocationService.onStart(LocationService.java:45)
04-26 14:54:35.359: W/System.err(11976): at android.app.Service.onStartCommand(Service.java:428)
04-26 14:54:35.359: W/System.err(11976): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2043)
04-26 14:54:35.359: W/System.err(11976): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
04-26 14:54:35.359: W/System.err(11976): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
04-26 14:54:35.359: W/System.err(11976): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 14:54:35.359: W/System.err(11976): at android.os.Looper.loop(Looper.java:130)
04-26 14:54:35.359: W/System.err(11976): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-26 14:54:35.359: W/System.err(11976): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 14:54:35.359: W/System.err(11976): at java.lang.reflect.Method.invoke(Method.java:507)
04-26 14:54:35.359: W/System.err(11976): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-26 14:54:35.359: W/System.err(11976): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-26 14:54:35.359: W/System.err(11976): at dalvik.system.NativeStart.main(Native Method)