You can use the PolyUtil.isLocationOnPath
method from the Google Maps Android API Utility Library:
Computes whether the given point lies on or near a polyline, within a specified tolerance in meters. The polyline is composed of great circle segments if geodesic is true, and of Rhumb segments otherwise. The polyline is not closed -- the closing segment between the first point and the last point is not included.
public static boolean isLocationOnPath(LatLng point, List<LatLng> polyline, boolean geodesic, double tolerance)
You will need to iterate over your markers and make them visible or invisible depending on the returned value of PolyUtil.isLocationOnPath
with your desired tolerance (500 in your example):
for(Marker marker : markers) {
if (PolyUtil.isLocationOnPath(marker.getPosition(), yourRoutePath, false, 500)) {
marker.setVisible(true);
} else {
marker.setVisible(false);
}
}