Android allows us to integrate google maps in our application. You can show any location on the map , or can show different routes on the map e.t.c. You can also customise the map according to your choices.
Google Map – Layout file
Now you have to add the map fragment into the xml layout file. Its syntax is given below −
<fragment
android:id=”@+id/map”
android:name=”com.google.android.gms.maps.MapFragment”
android:layout_width=”match_parent”
android:layout_height=”match_parent”/>
Google Map – AndroidManifest file
The next thing you need to do is to add some permissions along with the Google Map API key in the AndroidManifest.XML file. Its syntax is given below −
<!–Permissions–>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”com.google.android.providers.gsf.permission.
READ_GSERVICES” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />
<!–Google MAP API key–>
<meta-data
android:name=”com.google.android.maps.v2.API_KEY”
android:value=”AIzaSyDKymeBXNeiFWY5jRUejv6zItpmr2MVyQ0″ />
Customising Google Map
You can easily customise google map from its default view , and change it according to your demand.
Adding Marker
You can place a maker with some text over it displaying your location on the map. It can be done via addMarker() method. Its syntax is given below −
final LatLng TutorialsPoint = new LatLng(21 , 57);
Marker TP = googleMap.addMarker(new MarkerOptions()
.position(TutorialsPoint).title(“TutorialsPoint”));
Changing Map Type
You can also change the type of the MAP. There are four different types of map and each gives a different view of the map. These types are Normal,Hybrid,Satellite and terrain. You can use them as below
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
Enable/Disable zoom
You can also enable or disable the zoom gestures in the map by calling the setZoomControlsEnabled(boolean) method. Its syntax is given below −
googleMap.getUiSettings().setZoomGesturesEnabled(true);
Apart from these customization, there are other methods available in the GoogleMap class that help you customise the map. They are listed below −
Sr.No | Method & description |
1 | addCircle(CircleOptions options)This method add a circle to the map |
2 | addPolygon(PolygonOptions options)This method add a polygon to the map |
3 | addTileOverlay(TileOverlayOptions options)This method add tile overlay to the map |
4 | animateCamera(CameraUpdate update)This method Moves the map according to the update with an animation |
5 | clear()This method removes everything from the map. |
6 | getMyLocation()This method returns the currently displayed user location. |
7 | moveCamera(CameraUpdate update)This method repositions the camera according to the instructions defined in the update |
8 | setTrafficEnabled(boolean enabled)This method Toggles the traffic layer on or off. |
9 | snapshot(GoogleMap.SnapshotReadyCallback callback)This method Takes a snapshot of the map |
10 | stopAnimation()This method stops the camera animation if there is one in progress |