Step by Step Google Maps Implementation in Android App | Google Maps in Android: Step-by-Step Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] .com guys in this video I will show you how you can Implement Google Maps in your Android application so first of all you need to create a new Android project and as you can see here we I have already created a new Android project so first of all open up your browser and I will provide this link in the description below so this is the maps SDK for in Android and this is a official documentation from the Android and if we scroll down so as you can see here we have add the API key to your app so first of all we need to add the API game and to add the API key first of all we need to create the Google Maps API key so I will show you in this video how you can create the Google Map API key so don't worry about it and as you can see here we can follow this tip from the official documentation so first of all let me show you how you can create a Google Maps API key so [Music] simply type console dot developer okay and open the first one the first thing okay and make sure you are login with your email so as you can see here I already logged in with my email and as you can see I don't have any project here so if you have any uh any kind of existing project so you can use their project but if you don't have any projects so you can create a new project from here so simply click on create project and as you can see here and this is our project name so I will just name it Google Maps project okay and you can give any name you which you want and I will just simply click on this create so it will create our project okay guys so as you can see here our project is created and now what we will do we need to enable the API of Google Map okay so simply click on this enable apis and services so as you can see here we have a lot of apis so what we need what we need for this video we need the map SDK for Android so simply click on this okay and click on enable so it will enable Maps SDK for Android okay guys so as you can see here our API is enabled and now what we will do we will create a new API key for our Google map to use in our Android applications so as you can see here on the left side credentials so click on credentials and right now we don't have any credential okay so simply click on this create credentials and select the API key okay so this is our API key and I will just simply copy it and I close it and if I click on this API key one so it will also show us our API key and we can we can also add the restrictions on our API key so if I click on this Android app so this API key will be restricted to only Android application but for that we need to add the Sha here and to create the Sha audio certificate you you need to copy this command and paste it in your industry row terminal and you will get the sha1 key for your Android application but I will just set it to none and if you are using this key for your production application so I will recommend you to use this restriction on your Android application or your iOS or IP addresses okay so I will just simply set it to none and now I will go back to the documentation and first of all I need to add the Google Maps dependency so I will scroll down and as you can see here and this is the Google Maps dependency and I will copy it I will go back to the Android studio and here I will open build.gradle and as you can see here we have dependencies here so I will just simply paste the dependency here I will click on sync now now I will close this and if I go back to that documentation so now as you can see here we need to add the metadata so I will just simply copy this metadata and I will go back to the Android studio and I will open the Manifest here so I need to add we need to add this metadata in inside this application text so I will just simply paste it here and as you can see here this is our map API but we will store our Maps API key in our string.xml okay so I will just simply open this string dot XML and I will create a string here my API key okay and I will go back to the browser and I will just simply copy the API key and I will paste it here now what I will do I will just simply replace this with or I can slowly type string my API key so uh this is our API key and we are accessing it in our metadata okay so I will close the Manifest file in a string and now if I go back to the documentation so as you can see here and this is our XML codes so we need to use the fragment and I will just simply copy this fragment from here and I will go back to my Android studio and here we need to replace this text view with that fragment so I will just simply paste it here and I will remove this namespaces and I will also remove this and as you can see here this line is important this is uh the support my fragment okay so if you want to change the ID so you can change it but I will leave as it is okay so our XML file is ready now I will go back to the main activity and if I show you the official admination code so as you can see here this is the maps activity but we are implementing Google map from scratch and we need to implement the on map ready okay so first of all I will implement the on map ready callback on map ready callback and it it will give us an error so if you click on this red bullet Implement method so we will implement the on mapreddy method okay and why we are implementing this method because uh if we if we want to load our map in oncreate so the map the Google Maps take some milliseconds to load so if we if we load in oncreate so it will give us the null pointer exception okay so uh we will load the map when the map is ready okay so I will create a Google map variable here object here so simply type Google Map I will name it my map okay and here we need to get the fragment so simply type support mail fragment and I will name it my fragment is equal to get so for fragment manager Dot Point fragment by ID and I will just simply type the ID of what I mean so it is map okay and I will add the semicolon and as you can see here we got another error here and this error is about typecasting because and this shows the required types of support May fragment and provided fragment because we are finding the fragment and if if I remove this ID and okay let me remove all these so I will show you why this is as you can see here the fine fragment by ID returning a fragment but we need the support map fragment okay so I will add this ID and we will type we will cast it to May fragment it's very support map fragment okay so let me add the semicolon and if you click on this red bullet so it will say cost to uh com.google Android GMS map support my fragment so as you can see here we we casted this support my fragment to my fragment and below here what I will do I will just simply call my map fragment git map essing and I will pause this because we are we are implementing the on mapreddy callback okay so now what we will do we will do our work inside this on map ready so first of all I will initialize the Google Maps so my map is equal to Google Map okay so we will initialize the above Google Map variable to this Google Map okay and now what we will do we need to add some latitude and longitude so simply type late link I will name it Sydney I get this default netline you can use your latitude and longitude okay is equal to new rattling and I will just pass the latitude here so the latitude is minus 34 comma one five one so it will give us the Sydney latitude and longitude okay now what we will do I will call my map hope you have my email Dot add marker so inside the air marker simply type new marker options marker options dot position so pause the Sydney this is our latitude and longitude and a title so I will add a title save me you can you can add your title if you want okay and below here my map we will move the camera so move camera and simply use the camera update Factory dot new latitude language settings okay so our application is ready and now we will run our application okay guys so as you can see here our map is loaded and if I zoom it in so it shows the Sydney because we are passing the latitude and longitude of Sydney okay so you can watch your late length in your Google Map okay so that's it for this video guys and if you like this video please share this video with your friends and also make sure you are subscribed to my channel and the bell notification option is on so you won't miss the upcoming videos
Info
Channel: CodingZest
Views: 29,368
Rating: undefined out of 5
Keywords: CodingZest, Step by Step Google Maps Implementation in Android Application, how to implement google map in android studio, google map in android studio, google map in android studio tutorial, Easy Google Maps Implementation in Android, Google Maps in Android: A Step-by-Step Guide, android studio google maps, android studio google maps not working, android studio google map api, google maps android studio tutorial, google maps android tutorial, google maps android java
Id: pOKPQ8rYe6g
Channel Id: undefined
Length: 11min 41sec (701 seconds)
Published: Thu Feb 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.