Does not google maps load me with the location?

0

I am developing a bus application where according to the user's location it tells me that bus is closer to my position to be able to get to X place but my main problem is that I can not get the app to detect my location.

On the map:

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapaComoLLegar extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private Marker marcador;
double lat = 0.0;
double lng = 0.0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mapa_como_llegar);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    miUbicacion();

}

private void agreagarMarcador(double lat, double lng) {
    LatLng coordenadas = new LatLng(lat, lng);
    CameraUpdate miUbicacion = CameraUpdateFactory.newLatLngZoom(coordenadas, 16);
    if (marcador != null) marcador.remove();
    marcador = mMap.addMarker(new MarkerOptions()
            .position(coordenadas)
            .title("Mi posicion actual")
            .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher)));
    mMap.animateCamera(miUbicacion);
}

private void actualizarUbicacion(Location location) {
    if (location != null) {
        lat = location.getLatitude();
        lng = location.getLongitude();
        agreagarMarcador(lat, lng);
    }
}

LocationListener locListener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
        actualizarUbicacion(location);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {

    }
};
private static final int PETICION_PERMISO_LOCALIZACION = 101;
    private void miUbicacion() {
    if (ActivityCompat.checkSelfPermission(this, 
Manifest.permission.ACCESS_FINE_LOCATION) != 
PackageManager.PERMISSION_GRANTED && 
ActivityCompat.checkSelfPermission(this, 
Manifest.permission.ACCESS_COARSE_LOCATION) != 
PackageManager.PERMISSION_GRANTED) {
      //  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
        //        PETICION_PERMISO_LOCALIZACION);
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        actualizarUbicacion(location);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 15000, 0, locListener);
    }else return;

    }
}

I need help to know that it is wrong or because it does not load, when compiling it only stays on the map without showing the marker or moving the camera.

    
asked by Koki Senpai 04.10.2018 в 16:16
source

0 answers