- Learning Android Google Maps
- Raj Amal W.
- 382字
- 2021-07-09 21:54:30
Adding permissions and defining the API key
The permissions and API key must be defined in the AndroidManifest.xml
file, which provides essential information about applications to an operating system. The OpenGL ES version must be specified in manifest, which is then required to render the map and also different versions of Google Play services.
Adding permissions
Three permissions are required for our map application to work properly.
The permissions should be added inside the <manifest>
element. The four permissions are as follows:
- INTERNET
- ACCESS_NETWORK_STATE
- WRITE_EXTERNAL_STORAGE
- READ_GSERVICES
Let's now take a look at what these permissions are for.
This permission is required for our application to gain access to the Internet. Since Google Maps mainly works on real-time Internet access, access to the Internet is essential.
This permission is required to write data to an external storage. In our application, it is required to cache map data to an external storage.
This gives permission to read Google services.
The permissions are added to AndroidManifest.xml
as follows:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
There are some more permissions that are currently not required. We will learn about these in later chapters.
Specifying the Google Play services version
The Google Play services version must be specified in manifest for the functioning of maps. It must be within the <application>
element.
Add the following code to AndroidManifest.xml
:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Specifying the version 2 of OpenGL ES
Android Google maps uses OpenGL to render the map. Google maps will not work on devices that do not support version 2 of OpenGL. Hence, it is necessary to specify this in the manifest.
It must be added within the <manifest>
element similar to permissions. Add the following code to AndroidManifest.xml
:
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
The preceding code specifies that version 2 of OpenGL is required for the functioning of our application.
Defining the API key
The Google maps API key is required to provide authorization to the Google maps service. It must be specified within the <application>
element.
Add the following code to AndroidManifest.xml
:
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY"/>
The API_KEY
value must be replaced with the API key we noted earlier in the Google Developer Console.
The complete AndroidManifest
structure after adding permissions, specifying OpenGL, the Google Play services version, and defining the API key, is given as follows:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.raj.sampleapplication" android:versionCode="1" android:versionName="1.0" > <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <application> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyBVMWTLk4uKcXSHBJTzrxsrPNSjfL18lk0"/> </application> </manifest>
- C++ Primer習(xí)題集(第5版)
- 基于粒計算模型的圖像處理
- INSTANT FreeMarker Starter
- PyTorch自然語言處理入門與實戰(zhàn)
- Learning AWS Lumberyard Game Development
- Learning Firefox OS Application Development
- Python Data Analysis(Second Edition)
- Backbone.js Blueprints
- R Deep Learning Cookbook
- QGIS Python Programming Cookbook(Second Edition)
- SciPy Recipes
- MINECRAFT編程:使用Python語言玩轉(zhuǎn)我的世界
- Qt5 C++ GUI Programming Cookbook
- Oracle數(shù)據(jù)庫編程經(jīng)典300例
- Groovy 2 Cookbook