Google Cloud Platform, Redirect to that URL and log in with your Google account. If you are new here then you need to create a project first. If the project already exists then you can go inside it.
Click on the side menu and you’ll be shown with a sidebar with some options where you can click on “APIs & Services->Credentials”, which will redirect you to the credentials page where we can create our API keys inside it.
On top there will be a label called “create credentials”. When you click on it, it’ll drop you options where you can create different keys for different integrations. As of now we need to click on the API key. Inside the API key creation, we need to paste our package name and SHA-1 key which we generated a second ago.
You can find out your package name in Manifest or Gradle file. But make sure we need to restrict to Android inside the API key creation in order to make work on only android apps.
Once we are done with all those above steps click on save. We are done with the generating API key. Copy the API key and keep it aside for a minute.
Now come back to Android Studio and it's time for coding. Add dependency of google map in order to access all the functionalities into our application.
dependencies { Implementation 'com.google.android.gms:play-services-maps:16.1.0' }
After adding it now it’s time to do some code in the Manifest file. Go to Manifest file and place this code. Replace your API key inside the value which you’ve recently generated in Google Console.
ACCESS_NETWORK_STATE INTERNET ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION
Add all these permissions inside the Manifest file.
Coming back to the MapActivity you need to design your map using fragments. Place this fragment in your MapActivity XML file.
fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity" android:name="com.google.android.gms.maps.SupportMapFragment"
Fragment is also known as 360 degree activity where we can use it for maps and normal screens too.
In MapActivity you need to call the Support Map Fragment which you’ve declared in the xml file. You need to initialize it inside the onCreate method.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this);
When you initialize it, It’ll ask you to implement the method of maps which is known as “onMapReady()”. Simplest way to implement the method is: Place your cursor on “getMapAsync(this)” and press “Alt+Enter”. It’ll ask you to implement the method automatically.
Now you can see a method name called “onMapReady()”.
@Override public void onMapReady(GoogleMap googleMap) { }
Inside this method you can place your markers on a map wherever you want, You can animate your camera, Markers can be customized and a lot more.
For placing markers you need lat lon of any place where you wanted to show. Market Options class is used to do that thing.
double latitude = ; double longitude = ; MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps "); googleMap.addMarker(marker);
Wanted to change the color of the marker which you’ve created? Then use the below code.
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
By creating a marker you’ll always get the default marker icon. You can just change colors from it. If you want to place your own marker then we need to do like this. Place your image inside the drawable/mipmap folder and use it like below.
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon)));
When we load maps we always want to zoom to a particular location without user interference. We can animate our map using the Animate Camera class in it.
CameraPosition cameraPosition = new CameraPosition.Builder().target( new LatLng(17.385044, 78.486671)).zoom(12).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
As we all know that map has different types in it. We all are well known to google maps on our mobile devices.
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);
Note - By default google maps are set to NORMAL.
googleMap.setMyLocationEnabled(true); googleMap.getUiSettings().setZoomControlsEnabled(false); googleMap.getUiSettings().setZoomGesturesEnabled(false); googleMap.getUiSettings().setCompassEnabled(true); googleMap.getUiSettings().setMyLocationButtonEnabled(true); googleMap.getUiSettings().setRotateGesturesEnabled(true);
As I’ve shown the basic functionalities used in map, Google provides a lot more things in it.
Note - After all this stuff you need to enable Google Maps API in Google console in order to run your application.
Tips to Hire a Mobile app development Company that can grab your vision.
Develop your first android mobile application using google maps integration with Amar Infotech. In case any of your questions remain unanswered, you can directly talk to us, or leave us an email at sales@amarinfotech.com.
Understand what drives customer satisfaction and loyalty through their genuine feedback and insights.
We've been working with Amar Infotech since 2014 on our project, Lyrics Guru. Their team provided top-notch Flutter Mobile App development along with a Laravel admin panel, perfectly meeting our needs.
Over the years, their consistent support and expertise have been invaluable to us.
We highly recommend Amar Infotech for their exceptional service and dedication to client success.
Hi, I'm Philipp Müller, CEO of a Tour and Travel Agency in Sri Lanka. We chose Amar Infotech to bring our website to life with their Tour Package Extranet Services.
hey delivered excellent service, developing a Laravel-based backend that allows us to create and customize our own tour packages easily.
I highly recommend Amar Infotech for their professionalism and expertise in web development.
Hello, my name is Tito. We would like to extend our gratitude to Amar Infotech for their invaluable assistance in developing our website and app.
They were extremely helpful throughout the entire journey, guiding us every step of the way. Their professionalism is second to none.
Thanks to them, we now have a fully functional Flight Booking website that perfectly meets our needs.
I am the owner of Sammy Tours Sri Lanka, and I am thrilled with Amar Infotech for designing and developing my travel and tourism website.
They created a custom website that perfectly showcases our tour packages for Sri Lanka. Their expertise and dedication have significantly impacted our business.
I highly recommend Amar Infotech for their exceptional service and commitment to excellence.
Select the ideal remote team tailored to your business needs.
Enjoy up to 30% savings with our competitive solutions.
Leverage the expertise of over 100 skilled IT professionals.
Ensure success with agile project management and consistent, reliable outcomes.
Benefit from cutting-edge technology and creative approaches that drive your business forward.
Discover how we drive success with innovative solutions tailored for your needs. Get a comprehensive overview of our expertise and achievements in just one click.
Download NowExpanding horizons with a global network of representatives dedicated to delivering excellence across borders.
4th Floor, Sunrise Avenue, Stadium - Commerce Six Road, Ahmedabad, INDIA
sales@amarinfotech.comAI Jones (Account Executive), Phoenix, AZ 85013, 1.623.205.2415
ajones@amarinfotech.comRonak Patel (Sales Person), 64 caranci crescent Brampton ON Canada
ronak@amarinfotech.comJessica (Sales Person), 9 nirimba drive quackers hill nsw 2763
jessica@amarinfotech.comAdam (Sales Person) in Breda, Netherlands
adam@amarinfotech.com