J'ai Voici le code à l'aide de pour dessiner une polyline em> entre ces deux points: p> et to Problème: strong> p> forte> Solution: strong> p> i a essayé beaucoup em> 3 marqueurs code> sur une carte Google.
deux marqueurs code> em> pour montrer
points de départ et de fin code> li>
ol>
un marqueur code> em> pour afficher
Emplacement actuel code> [HUE_ROSE] LI>
ol>
Animate Marker à l'emplacement actuel code> em> Utilisation: p>
Obtenir un marqueur d'animation, mais le côté droit de la polyline code> em> p>
Comment montrer le marqueur animé sur le chemin de polyligne code> em> p>
solution code> em> pour celui-ci, mais
n'a pas trouvé code> aucune chose, partagez votre
suggestions code>. P> p>
3 Réponses :
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)));
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; }
Time Saver: Prenez le chemin le plus court sur le 180ème méridien code>
// 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 ;)
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 ...