Comment puis-je montrer emplacement actuel sur une Carte Google maps sur Android Guimauve?

Je veux google maps pour afficher l'emplacement de l'utilisateur. J'ai essayé ce code mais il ne fonctionne pas sur Android 6.

private GoogleMap map;
LocationManager lm;
LocationListener ll;
Location l;
LatLng pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start_layout);
lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
ll = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
l = (Location) location;
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
};
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.nMap);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
lm.requestLocationUpdates(lm.NETWORK_PROVIDER, 0, 0, ll);
}
pos = new LatLng(l.getLatitude(), l.getLongitude());
//Add a marker in Sydney and move the camera
map.setMyLocationEnabled(true);
map.addMarker(new MarkerOptions().position(pos).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(pos));
}

Voici les autorisations, j'ai mis:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
  • En quoi il n'a pas de travail? Crash? Mauvais endroit? Vérifiez aussi votre logcat pour toutes les erreurs et de les poster ici.
InformationsquelleAutor Z4F1 | 2016-01-03