|
Página 1 de 1
|
[ 1 Mensagem ] |
|
Current Location Não está funcionando corretamente
Autor |
Mensagem |
FFAGIANI
What is Android?
Data de registro: 27 Mai 2018, 00:24 Mensagens: 1
|
 Current Location Não está funcionando corretamente
Olá Pessoal, estou tentando desenvolver uma app que que atualiza a localização a cada 2 seg, usando API Google. O Código não apresenta erro, mas não devolve a correta localização no mapa. public class MotoristaMapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener, GoogleApiClient. ConnectionCallbacks, GoogleApiClient. OnConnectionFailedListener, com. google. android. gms. location. LocationListener { private Marker currentLocationMarker; private LatLng currentLocationLatLong; FusedLocationProviderClient mFusedLocationClient; // LocationCallback nLocationCallback; // LocationResult nLocationResult; @Override public void onLocationChanged (Location location ) { nLastLocation = location; LatLng latLng = new LatLng (location. getLatitude(), location. getLongitude()); mMap. moveCamera(CameraUpdateFactory. newLatLng(latLng )); mMap. animateCamera(CameraUpdateFactory. zoomTo(11)); if (currentLocationMarker != null) { } currentLocationLatLong = new LatLng (location. getLatitude(), location. getLongitude()); MarkerOptions markerOptions = new MarkerOptions (); markerOptions. position(currentLocationLatLong ); markerOptions. title("localização atual"); markerOptions. icon(defaultMarker (HUE_BLUE )); } @Override public void onStatusChanged (String provider, int status, Bundle extras ) { } @Override public void onProviderEnabled (String provider ) { } @Override public void onProviderDisabled (String provider ) { } @Override protected void onCreate (Bundle savedInstanceState ) { super. onCreate(savedInstanceState ); setContentView (R. layout. activity_motorista_maps); //startLocationUpdates(); // 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); // mFusedLocationClient = LocationServices. getFusedLocationProviderClient(this); } public void onConnected (@Nullable Bundle bundle ) { startLocationUpdates (); } protected void startLocationUpdates () { nLocationRequest = new LocationRequest (); nLocationRequest. setInterval(1000 * 10); nLocationRequest. setFastestInterval(2000); nLocationRequest. setPriority(LocationRequest. PRIORITY_HIGH_ACCURACY); // new Google API SDK v11 uses getFusedLocationProviderClient(this) // LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(nLocationRequest, nlocationCallback, null); if (ActivityCompat. checkSelfPermission(this, Manifest. permission. ACCESS_FINE_LOCATION) == PackageManager. PERMISSION_GRANTED && ActivityCompat. checkSelfPermission(this, Manifest. permission. ACCESS_COARSE_LOCATION) == PackageManager. PERMISSION_GRANTED) { mMap. setMyLocationEnabled(true); } else { return; } /* nLocationCallback = new LocationCallback(); nLocationCallback.onLocationResult(nLocationResult.getLastLocation()); mFusedLocationClient.requestLocationUpdates(nLocationRequest, nLocationCallback, Looper.myLooper()); */ mFusedLocationClient. requestLocationUpdates(nLocationRequest, new LocationCallback () { @Override public void onLocationResult (LocationResult locationResult ) { // do work here onLocationChanged (locationResult. getLastLocation()); } }, Looper. myLooper()); } @Override public void onConnectionSuspended (int i ) { } @Override public void onConnectionFailed (@NonNull ConnectionResult connectionResult ) { } private GoogleMap mMap; GoogleApiClient nGoogleApiClient; Location nLastLocation; LocationRequest nLocationRequest; private LocationCallback nlocationCallback; @Override public void onMapReady (GoogleMap googleMap ) { mMap = googleMap; if (ActivityCompat. checkSelfPermission(this, Manifest. permission. ACCESS_FINE_LOCATION) != PackageManager. PERMISSION_GRANTED && ActivityCompat. checkSelfPermission(this, Manifest. permission. ACCESS_COARSE_LOCATION) != PackageManager. PERMISSION_GRANTED) { return; } //camera CameraPosition cameraPosition = new CameraPosition. Builder(). zoom(11). target(currentLocationLatLong ). build(); mMap. animateCamera(CameraUpdateFactory. newCameraPosition(cameraPosition )); // mMap.setMyLocationEnabled(true); // } public void setCurrentLocationMarker (Marker currentLocationMarker ) { this. currentLocationMarker = currentLocationMarker; }} tudo indica que o problema está na recuperação da localização, mas não estou enxergando o erro. mFusedLocationClient.requestLocationUpdates(nLocationRequest, new LocationCallback() { @Override public void onLocationResult(LocationResult locationResult) { // do work here onLocationChanged(locationResult.getLastLocation()); } }, Looper.myLooper());
}
alguém sabe me dizer o que estou fazendo de errado? abs,
|
27 Mai 2018, 00:36 |
|
|
|
Página 1 de 1
|
[ 1 Mensagem ] |
|
Quem está online |
Usuários vendo este fórum: adilson, aechiara, akaytatsu, Alan Unger, alexandreizumi, Alexandrercarvalho, amos, Anakin Skywalker, Analista, andre.hebeler, andrigo, ARAKINIDIO, AT-AT, betofigu, Biggs Darklighter, blurkness, Bravox, Bruto_JPO, btminzon, burujo, C-3PO, camilodev, careisjr, carlos rodrigues, Catapan, celson, craudiao, dalmeidabr, Darth Maul, Darth Plagueis, dchechetto, digiwise, DroidBot, Eduardo - Brasil, everaldo, fabiano_eletro, fabric01, faco, fcoroa, felipecomp19, FelipeOliveira, fernando neves, ffabiano, flaviocc, frances135, frankmendes, FVB, Gabriel Laet, gamito, Gomes, Guilherme, Guilherme Cobain, gusrp, helder, heliopassos, Henrique Ferraz, Idelto, inesfg, ixian, j-menezes, JackBlackJack, jacksonst, JairoCN, Javanês, Jota, JRSIQUEIRA, Juninhooooo, jwv, Katia, kecyobarros, kidush, kristopher, Lelinho, LucasNascimento, lucastgomes, lucianno, lufreitas, luizcesar, luizfilipe, luizneto79, marciosoliveira, Marini, martins, mayahaslinger, MBetioli, Michel, mtomazzi, nfaria, nishimura.ichigo, nocivus, nrsf, otpor, Patrick, paulo.esantos, paulovaz, pemam.com.br, pingumanbr, polonia, Rafael, ramonsiebra, raninhofernandes, renanpl, renatodondoni, rerp7, rfrafael, roberto caceres, robsonrg, rogeriopgomes, romuloff, romuloigor, ronanPlus, rtodao, scattonevi, sephct, silvio.carlos, sobrinho, srsilveira, thienne, ThiMatsu, Thitto, Toks, tonical, washington, wender, wilson.slima, woyzeck, wylken, xa:=zin, XPTO, Yoshihury, Yuri, yuri82 e 19 visitantes |
|
Você não pode criar novos tópicos neste fórum Você não pode responder tópicos neste fórum Você não pode editar suas mensagens neste fórum Você não pode excluir suas mensagens neste fórum Você não pode enviar anexos neste fórum
|
|