Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom controls to MapFragment in Google Maps Android API v2?

I have SupportMapFragment and I need to add custom controls into it for changing a map type. Calling getView(), I get NoSaveStateFramelayout and I don't think it is a good idea to add it directly into it or its children.

What is the best way how can I can add a button over my map for changing the map type?

like image 983
Tomáš Linhart Avatar asked Feb 28 '13 13:02

Tomáš Linhart


People also ask

How do I add a marker on Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I add a style to Google Maps?

Create a new styleIn the Google Cloud Console, go to the Map Styles page. Click Create Style, and choose the Google Map radio button. Click Save. In the Save and Publish Map dialog, enter a map name and optional description, and click Save.


1 Answers

I have decided to override onCreateView and encapsulate the map in the code.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
    View mapView = super.onCreateView(inflater, viewGroup, bundle);
    RelativeLayout view = new RelativeLayout(getActivity());
    view.addView(mapView, new RelativeLayout.LayoutParams(-1, -1));
    // working with view
    return view;
}

And it works as I needed.

like image 57
Tomáš Linhart Avatar answered Sep 21 '22 05:09

Tomáš Linhart