If you already have the key got the link below and add the fingerprint along with your android project package name
You also need to login to your google account
https://code.google.com/apis/console
Click on create new key. Add the fingerprint along with your android project package name.
You can see the api key above
Enable google map api v2 from services tab.
Then in manifest file under application tag
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>
Answer from Raghunandan on Stack OverflowIf you already have the key got the link below and add the fingerprint along with your android project package name
You also need to login to your google account
https://code.google.com/apis/console
Click on create new key. Add the fingerprint along with your android project package name.
You can see the api key above
Enable google map api v2 from services tab.
Then in manifest file under application tag
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my key"/>
Visit the API Console
Login with your Google acocunt and click the API Access tab. Your API key is listed there.
You will also need to enable Google Maps Android API v2 service for your API key. You can do that on the services tab via the toggle button.
Videos
As far as i ve checked, the api key should be in android manifest which will be used by the MapView that we are using in the app. But the problem is if i decompile my app, i can see my api key in the manifest.
I even checked the apk (cloned the repo found in android documentation website itself which has the example on implementing maps in project), its the same.
How to secure it? I saw that we can use google console and we can restrict the use of api, but still the api should be set in manifest and still it can be decompiled and misused. How to solve this?
Hello, I am about to use for the first time the google map api for android,
And apparently in order to display the app in your app context, you need to have the API key defined in the android manifest like this:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE"/>Isn't there any other way?
Isn't that dangerous? People can get your api key.
I read about restricting the api to your app, but is that enough? Are there bad stories about people who had a misadventure of missused map APIs? Despite restricting?
What other solutions to protect yourself from your API key abuse?
I recommend a simpler approach that involves taking advantage of an unlikely, but more specific asset folder to house your debug key. To set this up, create a file res/values/maps-apikey.xml with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="maps_apikey">[productionApiKey]</string>
</resources>
Then each developer locally will add a file derived from this one in res/values-v1/maps-apikey.xml where their debug API key is provided. At runtime, the Android system will favor the more specific version res/values-v1/maps-apikey.xml for all versions of Android (since all are at least on API level 1 or higher).
Source control systems like git and svn allow you to add an "ignore" file which directs the tools to ignore this res/values-v1/maps-apikey.xml file so that each developer does not accidentally commit it to the repository. To do this for git, simply add a file res/.gitignore which contains only the line values-v1 then commit this file.
To release your software, simply delete the res/values-v1/maps-apikey.xml file before exporting a release. The resulting APK will then reference the version in res/values/maps-apikey.xml which is your correct production key.
you are doing the right thing but not the right way I think. Declare your string in strings.xml like this :
<string name="googleMapsAPIKey">TheMagicKeyString</string>
<!-- You can add this at the end as comment to keep a copy of another key for instance, to exchange it between debug and production-->
Note that you didn't give the same name at your 2 strings... One is called debug and not the other.
Secure usage of Google Maps Platform API key in Android apps is described in Google Maps Platform documentation:
https://developers.google.com/maps/documentation/android-sdk/get-api-key#restrict_key
The trick is applying Android app restriction that consist of the package name of your app and SHA-1 fingerprint of your certificate. This restriction is set in your Google Cloud console and is not exposed anywhere in your source code.
If somebody tries to use your API key in unauthorized way they will get an error, because they need your private certificate to make the API key work.
So, there is no problem adding an API key in the source code in case you set an Android restriction properly.
Also, I would suggest having a look at the API key best practices article:
https://developers.google.com/maps/api-key-best-practices
I hope my answer clarifies your doubt.
You need to set your map key in your AndroidManifest.xml file. Between application tag.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your key" />
Refer https://www.answertopia.com/android-studio/an-android-studio-google-maps-android-tutorial/ for better understanding.
There seems no way to have google maps api key free without credit card. To test the functionality of google map you can use it while leaving the api key field "EMPTY". It will show a message saying "For Development Purpose Only". And that way you can test google map functionality without putting billing information for google map api key.
<script src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap" async defer></script>
Updated Answer
As of June11, 2018 it is now mandatory to have a billing account to get API key. You can still make keyless calls to the Maps JavaScript API and Street View Static API which will return low-resolution maps that can be used for development. Enabling billing still gives you $200 free credit monthly for your projects.
This answer is no longer valid
As long as you're using a testing API key it is free to register and use. But when you move your app to commercial level you have to pay for it. When you enable billing, google gives you $200 credit free each month that means if your app's map usage is low you can still use it for free even after the billing enabled, if it exceeds the credit limit now you have to pay for it.