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 check if (location == null) return "" . Correct some of this ... - pavel

2 answers 2

 private void showLocation(Location location) { if (location == null) { dataGPS1 = "00,0000"; dataGPS2 = "00,0000"; return; } dataGPS1 = formatLocation1(location); dataGPS2 = formatLocation2(location); } 
  • so doesn't work either - varg sieg
  • @VargSieg, So the problem is not in this part of the code. How do you show the text? - Vladyslav Matviienko
  • `file = new File (directory.getPath () +" / "+" "+ dataGPS1 +" "+ dataGPS2 +" "+" .jpg ");` - Varg Sieg
  • @VargSieg, and what exactly is not working there? What's wrong? - Vladyslav Matviienko
  • one
    @VargSieg Do you check whether the GPS is on or not? - Vladyslav Matviienko

Correct the function formatLocation1() and formatLocation2()

 if (location == null) return "00.0000"; 

From showLocation() remove the check for null

  • I suppose formatLocation2 is the same - Dmitry Chistik
  • Yes, it is logical, corrected the answer) - Ivan Vovk