7
votes

Animate Marker sur le chemin Polyline

J'ai 3 marqueurs sur une carte Google.

  1. deux marqueurs pour montrer points de départ et de fin

    Voici le code à l'aide de pour dessiner une polyline entre ces deux points: xxx

    1. un marqueur pour afficher Emplacement actuel [HUE_ROSE]

      et to Animate Marker à l'emplacement actuel Utilisation: xxx

      Problème:

      Obtenir un marqueur d'animation, mais le côté droit de la polyline

      Solution:

      Comment montrer le marqueur animé sur le chemin de polyligne

      i a essayé beaucoup solution pour celui-ci, mais n'a pas trouvé aucune chose, partagez votre suggestions .


3 commentaires

Jetez un coup d'œil à Cette question et réponses.


Vous pouvez partager votre projet de capture d'écran et de démonstration?


@Phanvanlinh Voir c'est ce que je voulais avoir à la fin: Stackoverflow.com/Questtions/46103680/MAP-AND-MOVING-Marker-u Sing-Google-Maps-API Si vous pouvez m'aider à obtenir cela, cela signifie que cela signifie Vous avez répondu à la fois aux questions :) J'ai déjà partagé le code de mien mis à jour dans les deux questions ...


3 Réponses :


1
votes

Essayez avec le réglage d'ancrage comme suit

mDetailPositionMarker = mDetailGoogleMap.addMarker(new MarkerOptions()
                    .position(newLatLonValue)
                    .anchor(0.5f, 0.5f)
                    .rotation(bearingValue)
                    .flat(true)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.biketopicon)));


0 commentaires

1
votes

Je suppose que vous avez 3 marqueur 1. Point de source 2. Point de destination 3. Marqueur en mouvement

Vous devez essayer de cette façon, il vous aidera P>

 private interface LatLngInterpolatorNew {
        LatLng interpolate(float fraction, LatLng a, LatLng b);

        class LinearFixed implements LatLngInterpolatorNew {
            @Override
            public LatLng interpolate(float fraction, LatLng a, LatLng b) {
                double lat = (b.latitude - a.latitude) * fraction + a.latitude;
                double lngDelta = b.longitude - a.longitude;
                // Take the shortest path across the 180th meridian.
                if (Math.abs(lngDelta) > 180) {
                    lngDelta -= Math.signum(lngDelta) * 360;
                }
                double lng = lngDelta * fraction + a.longitude;
                return new LatLng(lat, lng);
            }
        }
    }


//Method for finding bearing between two points
private float getBearing(LatLng begin, LatLng end) {
    double lat = Math.abs(begin.latitude - end.latitude);
    double lng = Math.abs(begin.longitude - end.longitude);

    if (begin.latitude < end.latitude && begin.longitude < end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)));
    else if (begin.latitude >= end.latitude && begin.longitude < end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 90);
    else if (begin.latitude >= end.latitude && begin.longitude >= end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)) + 180);
    else if (begin.latitude < end.latitude && begin.longitude >= end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 270);
    return -1;
}


1 commentaires

Time Saver: Prenez le chemin le plus court sur le 180ème méridien



1
votes
    // Animation handler for old APIs without animation support
private void animateMarkerTo(final Marker marker, final double lat, final double lng) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final long DURATION_MS = 3000;
    final Interpolator interpolator = new AccelerateDecelerateInterpolator();
    final LatLng startPosition = marker.getPosition();
    handler.post(new Runnable() {
        @Override
        public void run() {
            float elapsed = SystemClock.uptimeMillis() - start;
            float t = elapsed/DURATION_MS;
            float v = interpolator.getInterpolation(t);

            double currentLat = (lat - startPosition.latitude) * v + startPosition.latitude;
            double currentLng = (lng - startPosition.longitude) * v + startPosition.longitude;
            marker.setPosition(new LatLng(currentLat, currentLng));

            // if animation is not finished yet, repeat
            if (t < 1) {
                handler.postDelayed(this, 16);
            }
        }
    });
}
call this method inside onLocationChange method and pass location lat and lang then you will see a magic ;)

0 commentaires