I'm developing an Android App to incorporate the google maps api in a separate activity. But when I read tutorials it states the build target must be set to google api at project creation. My question is it possible to add the map to an existing project?
-
1Wat? You can certainly add a map, via MapFragment to an existing project. https://developers.google.com/maps/documentation/android/start – Charlie Collins Mar 06 '13 at 14:19
-
What API does your application target? – ingh.am Mar 06 '13 at 14:23
-
cool just checked out that tutorial,so If my project is targeting api 17 there is no need to specify the google api in the build target? – Brian Var Mar 06 '13 at 14:34
-
What is your minSdkVersion ? – ingh.am Mar 06 '13 at 14:42
4 Answers
I know this is an old question but I ran into this when I was trying to figure out how to add Google Maps to an existing Android Studio Project when my previous experience was adding the Google Maps API from the initial app creation.
In Android Studio, you can go with:
File --> New --> Google --> Google Maps Activity
Or right click your folder with all the Activities, and the above will still hold.
Let Android Studio sync and you'll be shown a generated xml file about your google map key. Copy paste the URL (it's the one that isn't indented) and then follow the instructions. You'll get a key after. Once you get your key, copy paste it to the "YOUR_KEY_HERE" string constant in the generated xml file and you're good to go.

- 7,179
- 17
- 78
- 150
The device must have Google play services installed for Google Maps Android v2
to run:
The API is now distributed as part of the Google Play services SDK, which you can download with the Android SDK Manager. To learn how to install the package, see Installing the Maps API SDK.
You will find these docs useful!
If your application is running v1, it's probably best to run a check to see if Google Play services
is installed, and if not use the old map. I've not tested it, but check the answer here for running that check. I've also found, from here you can do this:
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext();
if(status == ConnectionResult.SUCCESS) {
//Success! Do what you want
}
And use the following types to determine if Google Play Services is installed on the device:
public static int isGooglePlayServicesAvailable (Context context)
Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client.
Returns status code indicating whether there was an error. Can be one of following in ConnectionResult: SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID.
To add the map using a fragment you will need to do something like this:
private GoogleMap map;
private MapFragment mapFragment;
private void InitMap()
{
mapFragment = ((MapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_map));
map = mapFragment.getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setMyLocationEnabled(false);
}
For Google Maps Android v2 and fragments, as mentioned above, this is a great resource! Oh, and remember to use the Google Play services SDK
!
-
Have installed the google play services and the api so my emulator is set.Would you say the simplest way to add a map is using a map fragment? – Brian Var Mar 06 '13 at 14:35
-
It's not really a case of how simple it is, I will update my answer with how I do it. – ingh.am Mar 06 '13 at 14:36
-
Oh, it's worth noting that you must test this on a device. It will not work on the emulator. – ingh.am Mar 06 '13 at 14:45
You just have to change the Build Target of your project.
Under Eclipse, go to Window > Preferences > Android In the Project Build Target list, select one which provides Google APIs.
Note: this is only valid if targeting Google Maps API for Android v1. Google Maps API for Android v2 is provided by a library project

- 3,606
- 1
- 28
- 30
Open your Project properties > Android> See Option Library> Click ADD> google-play-services_lib option is there (Only if google play services is used already with all steps correctly done in some another project)

- 361
- 3
- 3