In previous Google Map Android API tutorial posts you have learned to setup google map in android app, to get current location with marker, to search in the map etc. But in this tutorial, you will learn to change the Google map types like satellite, terrain, hybrid etc using Google map android API v2.

After running this application you will see normal map. If you click the button satellite, there you see the google satellite map and if you click the button terrain, you will see terrain google map.


Google Maps Android API tutorial post becomes too longer, So, I have divided it into different part. So if you have not followed my previous google maps android api’s tutorials please go through part 1, part 2 and part 3 first.

Google Maps Android API Getting Started Tutorial: Part 1
Get Current Location - Google Maps Android API Tutorial: Part 2
Google Maps Android API Adding Search Bar: Part 3

How to Change Google Map Types in Android using Google Maps Android API V2

First open XML layout file of Google Map Android API Tutorial project and four new Buttons inside LinearLayout with onClick attributes for normal map, satellite map, terrain map and hybrid map before google map fragment. Following is the complete content of XML layout file.


In java activity file you need to add four methods that we add onClick attributes in our XML layout file onNormalMap, onSatelliteMap, onTerrainMap and onHybridMap. Now add mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); to show normal google map when normal button is clicked, add mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); to show google satellite map when button is clicked, add mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); to show terrain google map and mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); to show hybrid google map.

Following is the complete java code of maps activity file.


How to Change Google Map Types in Android using Google Maps Android API V2

Now run your Changing Map Types - Google Maps Android API Tutorial Part 4 application and click on the buttons Normal, Satellite, Terrain and Hybrid. You will see different maps in your android application which will look like above screenshot.

Post a Comment

Powered by Blogger.