Differences between MapView, MapFrament and SupportMapFragment
Asked Answered
B

1

16

I would know the differences because I'm developing an app and I would introduce Google Map API v2 for compiling above Android 2.3. Which should I use?

Broadleaved answered 28/4, 2015 at 12:28 Comment(2)
#15237262Karp
@Viherbar: Please check my answer. If it seems fine and helped to resolve your query then please approve it. Thanks in advance~Touchstone
T
20

MapView:

A View which displays a map (with data obtained from the Google Maps service). When focused, it will capture key-presses and touch gestures to move the map.

Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class.

Use it if you are going to add a map into a fragment. (you need to update each lifecycle to MapView).

See Google API Documentation

MapFragment:

A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.

Use it if you want to add a map into Activity class (not fragment because it will create a nested fragment and it´s a mess).

See Google API Documentation.

SupportMapFragment:

A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity's layout file simply

Use SupportMapFragment if you are targeting Android API levels below 12.

See Google API Documentation.

Touchstone answered 27/4, 2017 at 21:6 Comment(1)
Use this class only if you are targeting API 12 and above You wrote below API 12 which is not correct.Kayceekaye

© 2022 - 2024 — McMap. All rights reserved.