0

Last time I put the code on oncreate method which can successfully capture the device longitude and latitude but currently I run again and it show nothing please anyone can advice me on this question? original should be can found in last month but currently cannot found!

enter image description here enter image description here

The code is like this.

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        return;
    }
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000 , 0, (LocationListener) this);

    //get Location
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    la = String.valueOf(location.getLatitude());
    searchla.setText("Latitude: "+ la);

    lo = String.valueOf(location.getLongitude());
    searchlo.setText("Longitude: "+lo);

so did i miss out something?

Cracker Rex
  • 91
  • 14

3 Answers3

0

If it was me, I would test to see if the longitude and latitude are returning values. Try putting break points and see.

If they are, it's problem for conversion and if not, it's problem with retrieval. Not the answer but gives the problem a direction to look into.

Nero
  • 1,058
  • 1
  • 9
  • 25
  • I suspected a problem with the conversion but I was wrong. – Nero Nov 22 '17 at 14:30
  • I don't quite understand what u want to say? – Cracker Rex Nov 22 '17 at 14:31
  • Before I make any more comments, just to clarify the second image is what your application is currently showing, right? – Nero Nov 22 '17 at 14:34
  • yes. thats the problem. I did successfully got the longitude and latitude before today but today got new version then I updated and then this problem suddenly came out. What happen? – Cracker Rex Nov 22 '17 at 14:36
  • What I am saying is you need to check if your longitude and latitude are populated before you covert them into string. If they are not populated, you would expect to see at least Longitude and latitude written in your textview – Nero Nov 22 '17 at 14:39
  • But im using emulator to run the apps which should automatically to show it because i set it inside the oncreate method. – Cracker Rex Nov 22 '17 at 14:43
  • First, I would suggest you to debug the application and see if the longitude and latitude is populated or not. – Nero Nov 22 '17 at 14:47
  • E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40fe4c0 – Cracker Rex Nov 22 '17 at 14:51
  • I suspect something from research but tell me something. When you debug your application, is longitude and latitude populated? – Nero Nov 22 '17 at 14:58
0

If there is no other code places that affects visibility of textviews, the only part is permission scope. So the device has no permission and then it goes to out of scope.

blackkara
  • 4,900
  • 4
  • 28
  • 58
0

Maybe it seems a dummy answer but can you check if the location service (GPS) is activated on the emulator? On the second screen shot I do not see the Location On icon. If this is not the case: Since last time you (when it worked) have you switched the API version? It is the same emulator/settings?

EDIT: Marshmallow emulator problem - https://issuetracker.google.com/issues/37069061 Solution: update to a newer API version

fhery021
  • 317
  • 2
  • 7