在我的应用程序中,我想要当前位置。我成功地获得了经度和经度。现在我想完成那个lat的地址。这是我的代码:
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);
}
现在我想要的是,如果我认为我没有得到完整的地址,那么我想再尝试5次以获得完整的地址,如果那时也没有获得位置那么我只想发送纬度和经度。
任何建议都将受到赞赏。
这是我的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)