How to Draw Interactive Polyline on Route Google Maps V2 Android

How to draw interactive Polyline on route google maps v2 android

Instead of creating too many short Polylines just create one like here:

PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < list.size(); z++) {
LatLng point = list.get(z);
options.add(point);
}
line = myMap.addPolyline(options);

I'm also not sure you should use geodesic when your points are so close to each other.

how to draw poly line on google map in android

@Override
onResume() {

if (map != null) {

// Enable MyLocation Button in the Map

map.setMyLocationEnabled(true);

map.getUiSettings().setZoomControlsEnabled(false);

try {

LatLng point = new LatLng(Double.parseDouble(Latreccvier),
Double.parseDouble(Lonreccvier));

BitmapDescriptor icon = BitmapDescriptorFactory
.fromResource(R.drawable.reccivermarker);

MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(point);
markerOptions.icon(icon);
map.addMarker(markerOptions);
// map.addPolyline(options);
// // Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 14));
map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
} catch (Exception e) {
}

}

}




@Override
public void RealTimeLocation(int memberId, final double lat,
final double lng) {
// TODO Auto-generated method stub
runOnUiThread(new Runnable() {
public void run() {

Latreccvier = String.valueOf(lat);
Lonreccvier = String.valueOf(lng);

LatLng point1 = new LatLng(Double.parseDouble(Latreccvier),
Double.parseDouble(Lonreccvier));

cordinatelist.add(point1);

friendMarker.setPosition(point1);
// options.add(point1);


}
});
}

};

please replace this code

Drawing a route on Google Maps API v2

Call pl = map.addPolyline(po); after the loop to create one polyline and not to try to create 7000 polylines each one "one point longer" than the one before.

Android draw polyline maps V2

Found my problem.

I had the play services jar added to my project and for some reason everything of the maps V2 api worked except drawing lines.

I then added the play services project as a dependency and after I did that everything worked.

How to animate polyline on android?

Create two arraylist of latlng then create polyline by given method

private fun createPolyLine() {

val lineOptions = PolylineOptions()
lineOptions.width(6f)
lineOptions.color(ContextCompat.getColor(act!!, R.color.colorPrimary))
lineOptions.startCap(SquareCap())
lineOptions.endCap(SquareCap())
lineOptions.jointType(JointType.ROUND)
blackPolyLine = googleMap!!.addPolyline(lineOptions)

val greyOptions = PolylineOptions()
greyOptions.width(6f)
greyOptions.color(Color.GRAY)
greyOptions.startCap(SquareCap())
greyOptions.endCap(SquareCap())
greyOptions.jointType(JointType.ROUND)
greyPolyLine = googleMap!!.addPolyline(greyOptions)

animatePolyLine()
}

after that create animation of these polylines

private fun animatePolyLine() {
val animator = ValueAnimator.ofInt(0, 100)
animator.duration = 1500
animator.interpolator = LinearInterpolator()
animator.addUpdateListener { animator ->
val latLngList =
blackPolyLine!!.points
val initialPointSize = latLngList.size
val animatedValue = animator.animatedValue as Int
val newPoints = animatedValue * decodedPath.size / 100
if (initialPointSize < newPoints) {
latLngList.addAll(decodedPath.subList(initialPointSize, newPoints))
blackPolyLine!!.points = latLngList
}
}
animator.addListener(polyLineAnimationListener)
animator.start()
}

private var polyLineAnimationListener: Animator.AnimatorListener =
object : Animator.AnimatorListener {
override fun onAnimationStart(animator: Animator) {}
override fun onAnimationEnd(animator: Animator) {
val blackLatLng: MutableList<LatLng> = blackPolyLine!!.points
val greyLatLng: MutableList<LatLng> = greyPolyLine!!.points
greyLatLng.clear()
greyLatLng.addAll(blackLatLng)
blackLatLng.clear()
blackPolyLine!!.points = blackLatLng
greyPolyLine!!.points = greyLatLng
blackPolyLine!!.zIndex = 2f
animator.start()
}

override fun onAnimationCancel(animator: Animator) {}
override fun onAnimationRepeat(animator: Animator) {}
}


Related Topics



Leave a reply



Submit