Search code examples
androidgoogle-mapsgoogle-maps-api-2

Android Googlemaps V2 API Key Query?


I have been in the process of upgrading my Android Java app from Googlemaps V1 to V2 and it's being rather painful. I need to do all my display procedurally (i.e. no XML layout files) as it's a cross platform engine I've developed.

In V1 I could set the API key when creating the MapView via

String apikey = MySettings.getMapsKey();
MapView mapView = new MapView( activity, apikey );

This was excellent because I can build many apps all signed with different certificates and just give it different data files to work.

It looks like you have to set the API key in the Manifest file now via

        <meta-data  android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyD_LwdRJXXXxn9VdOgKWbPaVxH-YqX67-8" />

So the two questions are

  • Is my assumption correct that MapView is only for Googlemaps V1 so I have to ditch it to and start using MapFragment for support Googlemaps V2?
  • If we now have to use MapFragment is there any way to procedurally set this key rather than it being embedded in code/manifest?

Solution

  • 1) Yes, there is no other option than using a MapFragment (use SupprotMapFragment for API [v4-v10])

    2) There is no other way (at least documented) than setting the API key from the Manifest. It can be possible to obtain a meta-data in code and set is somehow to MapFragment using reflection, but the sources are closed and it is not worth the effort.

    And what can disappoint you more, the Marker InfoWindow is static and you can't set buttons or dynamic Views (ProgressBar, for instance). But generally I like it far more better than v1.