0

Good day to you all, I am creating a ride app and I was asking for some assistance in the following problem I am facing.

So, On the image below the grey background represents a google map fragment and above it sits two views(black) I wanted to know if it were possible to only show a polyline and markers between the black views only in the red area and have the rest of the map showing in the background as well.

If it helps I have managed to get the LatLng's of the corners of the red box using:

googleMap.getProjection().fromScreenLocation();

Thank you in advance!

example image

Brandon
  • 146
  • 8

1 Answers1

1

Yes, it is possible. Several ways. For example, the red area of your figure can be View (e.g. custom view) with transparent background and you can draw your polylines on it (you need to take into account position of transparent "red" view on map view for correction of fromScreenLocation()/toScreenLocation() methods results). Also, probably, you can use two MapViews one over another and synchronize its scrolling and zooming, but IMHO best way is to to implement custom view component based on MapVew (or MapFragment) an override onDraw() for MapVew-based (or dispatchDraw() for MapFragment-based) method like in this or that answers:

..
@Override
public void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    canvas.save();
    drawPolylinesInRegion(canvas);
    canvas.restore();
}
...

In drawPolylinesInRegion(canvas); method you should draw your polylines and markers "manually" converting coordinates of them via method opposite you mentioned: toScreenLocation() and taking into account size of "gray regions" of you example figure.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79