1 minute read

9.2. Creating and Adding an Api Key

Figure 9.3. google_maps_api.xml file

9.2. Creating and Adding an Api Key

Advertisement

In order to use Google Maps, we need to enter an api (application programming interface) key to the google_maps_api.xml file. The default google_maps_api.xml is as follows:

<resources>

<!-TODO: Before you run your application, you need a Google Maps API key.

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi ?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDRO ID&r=F7:42:43:B5:F0:19:50:79:4E:0E:69:D2:1A:27:3D:7D: E4:47:EC:6D%3Bcom.example.atomic.myapplication

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string> </resources>

Code 9.1

We have to enter the api key to the place indicated by YOUR_KEY_HERE in the file above. So, where should we obtain this key? We just need to go to the website indicated in our google_maps_api.xml file which starts with https://console.developers . When we navigate to this site, we need to select Create a new project and hit Continue as follows:

Figure 9.4. Creating a new project to obtain a new api key for the maps app

In the next dialog, please hit the Create API Key:

Figure 9.5. Creating the api key

Google console will then display the generated api key as shown below:

Figure 9.6. The generated api key

Please copy the generated api key and paste it to the place indicated in the google_maps_api.xml file:

<resources>

<!-TODO: Before you run your application, you need a Google Maps API key.

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi ?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDRO ID&r=F7:42:43:B5:F0:19:50:79:4E:0E:69:D2:1A:27:3D:7D: E4:47:EC:6D%3Bcom.example.atomic.myapplication

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyBiCCm62mCYYhXVFedpcDpxxxxx xxxx</string> </resources>

Code 9.2

Please note that you need to generate and paste your own key otherwise your app won‟t work.

This article is from: