
Problema con Google Direction API for Android.
Publicado por Luis Enrique (1 intervención) el 06/05/2017 23:25:36
[b]Buenos dias, tengo el siguiente problema:
Esta linea locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,15000,0, (android.location.LocationListener) locListener); me esta generando que se salga del app y bote error cada vez que entro a ella. segun tutoriales me dice que solo deberia poner locListener sin el parentisis detrás, pero al hacer esto el locListener me aparece subrayado como error. Alguna idea?
/b]
Esta linea locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,15000,0, (android.location.LocationListener) locListener); me esta generando que se salga del app y bote error cada vez que entro a ella. segun tutoriales me dice que solo deberia poner locListener sin el parentisis detrás, pero al hacer esto el locListener me aparece subrayado como error. Alguna idea?
/b]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package chamos.app.chapulo.com.jama;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Camera;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.location.LocationListener;
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 MapsActivity 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_maps);
// 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);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
miUbicacion();
}
private void agregarMarcador(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 posición 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();
agregarMarcador(lat, lng);
}
}
LocationListener locListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
actualizarUbicacion(location);
}
};
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) {
return;
}
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
actualizarUbicacion(location);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,15000,0, (android.location.LocationListener) locListener);
}
}
Valora esta pregunta


0