dimanche 17 juillet 2016

Get last known location always return NULL SDK 23

I want to get the user Location but the method always return null this is my Code :

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    SystemProvider = locationManager.getBestProvider(new Criteria(),true);
     UserLocation = locationManager.getLastKnownLocation(SystemProvider);
           if(UserLocation==null)
           {
               Log.i("Exc2","No Location");
               mMap.addMarker(new MarkerOptions().position(new LatLng(0,0)).title("No Location"));
               mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(0,0),10));
           }
           else {
               double one = UserLocation.getLatitude();
               double two = UserLocation.getLongitude();
               mMap.addMarker(new MarkerOptions().position(new LatLng(one, two)).title("HMS"));
               mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(one, two), 10));
           }

i have tried many ways but nothing happened even when I opened Google maps on the emulator and pressed on the gps button it was unable to get my current location thanks in advance

Aucun commentaire:

Enregistrer un commentaire