From some previous article we discuss about dynamic user interface in Android using library but today we discuss about how to add google map in your application using ExtraMaputils library.
Nowadays many of developers need to implement Google map in their application and many time they want some customization with Google map. That all thing you can do with ExtraMapUtils library which is a simple library for handle markers, polygons and polylines on google maps.
[tmh_ads]
Recommended article :
What you can do with ExtraMapUtils Library
- compatible with API Level 17
- provide multiple theme for google maps
- add multiple marker, polygon & polyline in simple way
- support Vector drawable for marker icon
- provide demo of using library in ListView
- lite mode supported
- get area of polygon & length of polyline supported

Now we go through the setup of this library
1. Provide the gradle dependency
Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
Add the dependency:
dependencies { compile 'com.github.bkhezry:ExtraMapUtils:1.1.0' }
2. Add your code
Add MapView to UI layout
<com.google.android.gms.maps.MapView android:id="@+id/mapLite" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="300dp" app:liteMode="true" app:mapType="normal" />
new ViewOptionBuilder() .withStyleName(ViewOption.StyleDef.RETRO) .withCenterCoordinates(new LatLng(35.6892, 51.3890)) .withMarkers(AppUtils.getListExtraMarker()) .withPolygons( AppUtils.getPolygon_1() ) .withPolylines( AppUtils.getPolyline_2(), AppUtils.getPolyline_4() ) .withForceCenterMap(false) .build();
After declare ViewOption add this code for show elements in maps
MapUtils.showElements(viewOption, googleMap, getActivity());
ViewOption attributes
Name | Type | Default | Description |
---|---|---|---|
title | String | @NullAble | use in demo as CardView tile |
centerLatLng | LatLng | @NullAble | center of Map |
forceCenterMap | boolean | false | force map moving to centerLatLng point |
mapsZoom | float | 14 | zoom of map when map moving to centerLatLng |
markers | ExtraMarker | @NullAble | list of ExtraMarker that showing on Map |
polygons | ExtraPolygon | @NullAble | list of ExtraPolygon that showing on Map |
polylines | ExtraPolyline | @NullAble | list of ExtraPolyline that showing on Map |
isListView | boolean | false | when using utils in ListView this parameter should be true. because fixing zoom of bounded map |
styleName | StyleDef | DEFAULT | style of google map |
declare ExtraMarker
new ExtraMarkerBuilder() .setName("Start") .setCenter(latLngs_3[0]) .setIcon(icons_2[0]) .build()
ExtraMarker attributes
Name | Type | Default | Description |
---|---|---|---|
name | String | @NullAble | label of Marker |
center | LatLng | @NoneNull | center of Marker |
icon | int | @NoneNull | icon of marker |
delare ExtraPolygon
new ExtraPolygonBuilder() .setPoints(latLngs_1) .setzIndex(0) .setStrokeWidth(10) .setStrokeColor(Color.argb(100, 0, 0, 0)) .setFillColor(Color.argb(100, 200, 200, 200)) .build();
ExtraPolygon attributes
Name | Type | Default | Description |
---|---|---|---|
points | LatLang[] | @NoneNull | list of point |
fillColor | int | none color | color of polygon filling |
uiOptions | UiOption | @NoneNull | some parameter of polygon |
declare ExtraPolyline
new ExtraPolygonBuilder() .setPoints(latLngs_1) .setzIndex(0) .setStrokeWidth(10) .setStrokeColor(Color.argb(100, 0, 0, 0)) .setFillColor(Color.argb(100, 200, 200, 200)) .build();
ExtraPolygon attributes
Name | Type | Default | Description |
---|---|---|---|
points | LatLang[] | @NoneNull | list of point |
fillColor | int | none color | color of polygon filling |
uiOptions | UiOption | @NoneNull | some parameter of polygon |
declare ExtraPolyline
new ExtraPolylineBuilder() .setPoints(latLngs_2) .setzIndex(0) .setStrokeWidth(10) .setStrokeColor(Color.argb(100, 255, 0, 0)) .build();
ExtraPolyline attributes
Name | Type | Default | Description |
---|---|---|---|
points | LatLang[] | @NoneNull | list of point |
uiOptions | UiOption | @NoneNull | some parameter of polyline |
UiOption attributes
Name | Type | Default | Description |
---|---|---|---|
strokeColor | int | Color.BLACK | line color |
strokeWidth | int | 10 | width of line |
zIndex | int | 0 | zIndex of polyline or polygon |
strokePattern | StrokePatternDef | Default | stroke pattern of line |
getArea() method in ExtraPolygon return Area of polygon in square meters. getLength method in ExtraPolyline return Length of polyline in meters.
Hope you like this tutorial and please comment us with your thought and suggestions.
Share your thoughts