Join FlipAndroid.COM Telegram Group: https://t.me/joinchat/F_aqThGkhwcLzmI49vKAiw


Animar un coche (Marcador) a lo largo de un camino en google map android

Voy a compartir una solución de mover un marcador a lo largo de la trayectoria si usted tiene lista. El mapa de bits se moverá a lo largo de la trayectoria de usar la lista de LatLng.

  • Android maps v2 se vuelve de baja calidad cuando el área del mapa se mueve automáticamente
  • Abrir mapa de la calle trabajando offline en Android
  • Cómo obtener latitud y longitud de la dirección en android
  • Android Map V2 - ¿Por qué MAPS_RECEIVE permiso?
  • La importación android.support.v7.app.MediaRouteActionProvider no se puede resolver
  • Android Make Disappear o eliminar el punto azul en el mapa v2
  • Android Maps V2 newLatLngBounds con rodamiento
  • Mover MapFragment (SurfaceView) hace que el fondo negro parpadee
  • 2 Solutions collect form web for “Animar un coche (Marcador) a lo largo de un camino en google map android”

    public static void setAnimation(GoogleMap myMap, final List<LatLng> directionPoint, final Bitmap bitmap) { Marker marker = myMap.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory.fromBitmap(bitmap)) .position(directionPoint.get(0)) .flat(true)); myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(directionPoint.get(0), 10)); animateMarker(myMap, marker, directionPoint, false); } private static void animateMarker(GoogleMap myMap, final Marker marker, final List<LatLng> directionPoint, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = myMap.getProjection(); final long duration = 30000; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { int i = 0; @Override public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); if (i < directionPoint.size()) marker.setPosition(directionPoint.get(i)); i++; if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } } }); } 

    También estoy hecho con este mismo escenario, aquí dado ese código.

     public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener { private static Location oldLocation; private GoogleMap mMap; private LocationManager locationManager; private Marker marker; private static float angle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(this, "Location permissioin in not enable", Toast.LENGTH_SHORT).show(); return; } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 0, this); mapFragment.getMapAsync(this); } @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; } @Override public void onLocationChanged(Location location) { locationUpdate(location); if (oldLocation != null) { double bearing = angleFromCoordinate(oldLocation.getLatitude(), oldLocation.getLongitude(), location.getLatitude(), location.getLongitude()); changeMarkerPosition(bearing); } oldLocation = location; } private void locationUpdate(Location location) { LatLng latLng = new LatLng((location.getLatitude()), (location.getLongitude())); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title("Current Position"); markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.car_right)); mMap.clear(); marker = mMap.addMarker(markerOptions); CameraPosition position = CameraPosition.builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) .zoom(19) .tilt(30) .build(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(position)); } private void changeMarkerPosition(double position) { float direction = (float) position; Log.e("LocationBearing", "" + direction); if (direction==360.0){ //default marker.setRotation(angle); }else { marker.setRotation(direction); angle=direction; } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } private double angleFromCoordinate(double lat1, double long1, double lat2, double long2) { double dLon = (long2 - long1); double y = Math.sin(dLon) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); double brng = Math.atan2(x, y); brng = Math.toDegrees(brng); brng = (brng + 360) % 360; brng = 360 - brng; return brng; }} 

    Espero que esto sea útil.

    FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.