There is GPS data that is reflected in the form of latitude 56,1922 and longitude 37,8615 . When the GPS receiver is turned off, the result is displayed as null null . There is a desire to change this result when the receiver is turned off to 00,0000 00,0000 , but something does not work out, there were different options, everything remains the same.
With this code, displays null null
private void showLocation(Location location) { if (location == null) return; dataGPS1 = formatLocation1(location); dataGPS2 = formatLocation2(location); } public String formatLocation1(Location location) {// НА ВХОД БЕРЁТ Location location if (location == null) //ЧЕТАЕТ ИЗ НЕГО ДАННЫЕ И ВЫДАЁТ СТРОКУ return ""; //ШИРОТА, ДОЛГОТА, ВРЕМЯ ОПРЕДЕЛЕНИЯ return String.format( "%1$.4f", location.getLatitude(), location.getLongitude()); } public String formatLocation2(Location location) {// НА ВХОД БЕРЁТ Location location if (location == null) //ЧЕТАЕТ ИЗ НЕГО ДАННЫЕ И ВЫДАЁТ СТРОКУ return ""; //ШИРОТА, ДОЛГОТА, ВРЕМЯ ОПРЕДЕЛЕНИЯ return String.format( "%2$.4f", location.getLatitude(), location.getLongitude()); } Trying to fix the same
private void showLocation(Location location) { if (formatLocation1(location).equals("null")){ dataGPS1="00,0000"; ; }else{ dataGPS1 = formatLocation1(location); } if (formatLocation2(location).equals("null")){ dataGPS2="00,0000"; }else{ dataGPS2 = formatLocation2(location); } }
formatLocation1(location).equals("null")definitely not possible, you yourself checkif (location == null) return "". Correct some of this ... - pavel