Wouldn’t it be nice if you could include the original and well popular ”Google Maps” in your Android app ? A quick , few simple steps can enable maps in your Android Studio project, and make your app facilitate to GPS, navigation , Location data and lots more.
Stop thinking from where Google Maps comes from, young developer. Generate an Google Maps API id and attach it to your project at the required file. The Google Maps is all yours to develop. Check out the following steps:
Steps to include Google Maps:
Creating a new Map Activity:
Open Android Studio. Give a suitable application name of your choice. Click next and select GoogleMaps Activity from the activity options list. When you click finish, And get the gradle build finished the output google_maps_api.xml will look like this.
Enabling Google Maps API:
Copy the highlighted URL in the above picture onto your browser. You’ll reach the official site of Google API credentials.
Click Continue. Wait for the API to become enabled. After the API is enabled, a new screen will pop up like this to generate the required API key.
Click Create API key button. An API key will be generated to incorporate Google Maps in your developing Android application.
Copy the generated ID and paste the key in “YOUR KEY HERE” in google_maps_api.xml. This will make the Google Maps function .
Setting a marker (location):
Open the MapsActivity.java from the main tab.
In the onMapReady() there is a default marker setting as Sydney. You can change this marker according to your desired loaction.
Give the desired lattitude and logitude in the LatLng() function. You can specify your location in the position() function. Add any text to the marker if necessary in the text portion,
I’ve developed a sample , where the marker is at the location of Taj Mahal, Agra, India.
Hope you guys will try it out..!!:) Happy learning..!!
Subscribe to Code Rewritten
Get the latest posts delivered right to your inbox