Ola Map Android SDK offers a comprehensive solution for integrating interactive map functionalities into your application. By utilizing the Maps SDK for Android, you can incorporate maps powered by Ola's data directly into your app.
Setting Up the SDK
Download SDK
You have to download the Android Map SDK from the link Android Map SDK and copy it to libs folder.
Add SDK Dependency
Include the SDK in your project by adding the following dependencies to your build.gradle
The Dynamic Map provides a comprehensive solution for integrating interactive map functionalities into your application. SDK supports dynamic maps with various interactive features:
Scroll
Zoom
Rotate
Tilt
Tracking users current location
2. Markers
Easily add markers to your map to highlight important locations or points of interest, customize marker icons and styles for a visually appealing representation of data
Adding a Marker
To add a marker to the map, you need to create an OlaMarkerOptions object with the desired properties and then use the addMarker method.
setMarkerId(String id): Sets a unique identifier for the marker.
setPosition(OlaLatLng position): Sets the position of the marker.
setIsIconClickable(Boolean isClickable): Enables or disables the marker's icon clickability.
setIconRotation(Float rotation): Sets the rotation angle of the marker's icon.
setIsAnimationEnable(Boolean isAnimationEnable): Enables or disables animations for the marker.
setIsInfoWindowDismissOnClick(Boolean isInfoWindowDismissOnClick): Sets whether the info window should be dismissed when clicked.
Removing a Marker
To remove a marker from the map, use the removeMarker method on the marker object.
marker1.removeMarker()
Updating a Marker
To update the an existing marker, use the appropriate method on the marker object.
marker1.setPosition(newPosition)
3. Infowindows
Display informative pop-up windows when users interact with markers or specific map areas. Infowindows can contain descriptive text and extra details enhancing user engagement.
Adding an Info Window
To add an info window to a marker, you need to create an OlaMarkerOptions object with the desired properties, including the snippet for the info window, and then use the addMarker method.
val markerOptions1 = OlaMarkerOptions.Builder()
.setMarkerId("1232")
.setPosition(olaCampus)
.setSnippet("This is the infowindow")
.setIsIconClickable(true)
.setIconRotation(0f)
.setIsAnimationEnable(true)
.setIsInfoWindowDismissOnClick(true)
.build()
marker1 = olaMap.addMarker(markerOptions1)
setMarkerId(String id): Sets a unique identifier for the marker.
setPosition(OlaLatLng position): Sets the position of the marker.
setSnippet(String snippet): Sets the text to be displayed in the info window.
setIsIconClickable(Boolean isClickable): Enables or disables the marker's icon clickability.
setIconRotation(Float rotation): Sets the rotation angle of the marker's icon.
setIsAnimationEnable(Boolean isAnimationEnable): Enables or disables animations for the marker.
setIsInfoWindowDismissOnClick(Boolean isInfoWindowDismissOnClick): Sets whether the info window should be dismissed when clicked.
Hiding an Info Window
To hide an info window from a marker, use the hideInfoWindow method on the marker object.
marker1.hideInfoWindow()
Updating an Info Window
To update the text in an existing info window, use the updateInfoWindow method on the marker object.
marker1.updateInfoWindow("This is an updated info window")
4. Polyline
Draw polylines to represent paths or routes on the map, ideal for navigation or tracking purposes. Customize polyline styles, including color and thickness, to enhance visual clarity.
Adding a Polyline
To add a polyline to the map, you need to create an OlaPolylineOptions object with the desired properties and then use the addPolyline method.
val points = arrayListOf(OlaLatLng(12.931423492103944, 77.61648476788898),
OlaLatLng(12.931758797710456, 77.61436504365439))
val polylineOptions = OlaPolylineOptions.Builder()
.setPolylineId("pid1")
.setPoints(points)
.build()
polyline1 = olaMap.addPolyline(polylineOptions)
setPolylineId(String id): Sets a unique identifier for the polyline.
setPoints(ArrayList<OlaLatLng> points): Sets the points that define the vertices of the polyline.
setColor(String color): Sets the color of the polyline.
setLineType(String lineType): Sets the line type of the polyline.
setWidth(Float width): Sets the width of the polyline.
Removing a Polyline
To remove a polyline from the map, use the removePolyline method on the polyline object.
polyline.removePolyline()
Updating Polyline
To update other properties of an existing polyline, use the respective methods on the polyline object.
Easily draw circles on the map around specific points, useful for showcasing coverage areas or proximity. Adjust the circle's radius and style to fit your application’s needs.
Adding a Circle
To add a circle to the map, you need to create an OlaCircleOptions object with the desired properties and then use the addCircle method.
val olaCampus = OlaLatLng(12.931423492103944, 77.61648476788898)
val circleOptions = OlaCircleOptions.Builder()
.setOlaLatLng(olaCampus)
.setRadius(100f)
.build()
circle = olaMap.addCircle(circleOptions)
setOlaLatLng(OlaLatLng position): Sets the position of the circle's center.
setCenter(OlaLatLng center): Sets the center of the circle.
setRadius(Float radius): Sets the radius of the circle in meters.
setColor(String color): Sets the color of the circle.
setBlur(Float blur): Sets the blur radius of the circle.
setBorderOptions(BorderOptions borderOptions): Sets the border options of the circle.
setOpacity(opacity: Float): Sets the opacity of the circle.
Removing a Circle
To remove a circle from the map, use the removeCircle method on the circle object.
circle.removeCircle()
Updating a Circle
To update other properties of an existing circle, use the respective methods on the circle object.
circle.setColor("#FF0000")
6. Polygon
Create multi-sided shapes to represent areas or boundaries on the map, perfect for zoning or highlighting regions of interest. Customize polygon fill colors and borders to enhance visibility and distinction.
Adding a Polygon
To add a polygon to the map, you need to create an OlaPolygonOptions object with the desired properties and then use the addPolygon method.
val points = arrayListOf(
OlaLatLng(18.56892987516166, 73.88081911869274),
OlaLatLng(18.58960286647498, 73.83615669644608)
)
val polygonOptions = OlaPolygonOptions.Builder()
.setPolygonId("polygon1")
.setPoints(points)
.build()
polygon = olaMap.addPolygon(polygonOptions)
setPolygonId(String id): Sets a unique identifier for the polygon.
setPoints(ArrayList<OlaLatLng> points): Sets the points that define the vertices of the polygon.
setColor(color: String): Sets the color of the polygon.
setBorderOptions(borderOptions: BorderOptions): Sets the border options of the polygon.
Removing a Polygon
To remove a polygon from the map, use the removePolygon method on the polygon object.
polygon.removePolygon()
Updating a Polygon
To update other properties of an existing polygon, use the respective methods on the polygon object.
Implement smooth, curved lines between points on the map, offering a visually appealing way to represent routes or connections. Customize the control points to shape the curve and achieve the desired aesthetic.
Adding a Bezier Curve
To add a Bezier curve to the map, you need to create a BezierCurveOptions object with the desired properties and then use the addBezierCurve method.
val startPoint = OlaLatLng(12.931423492103944, 77.61648476788898)
val endPoint = OlaLatLng(12.931758797710456, 77.61436504365439)
val bezierCurveOptions = BezierCurveOptions.Builder()
.setCurveId("bcurve1")
.setStartPoint(startPoint)
.setEndPoint(endPoint)
.build()
bezierCurve = olaMap.addBezierCurve(bezierCurveOptions)
setCurveId(String id): Sets a unique identifier for the Bezier curve.
setStartPoint(OlaLatLng startPoint): Sets the starting point of the Bezier curve.
setEndPoint(OlaLatLng endPoint): Sets the ending point of the Bezier curve.
setPoints(startPoint: OlaLatLng, endPoint: OlaLatLng): Sets the starting and ending points of the Bezier curve.
setColor(color: String): Sets the color of the Bezier curve.
setLineType(lineType: String): Sets the line type of the Bezier curve.
setWidth(width: Float): Sets the width of the Bezier curve.
Removing a Bezier Curve
To remove a Bezier Curve from the map, use the removeBezierCurve method on the Bezier Curve object.
bezierCurve.removeBezierCurve()
Updating a Bezier Curve
To update other properties of an existing Bezier Curve, use the respective methods on the Bezier Curve object.
val newStartPoint = OlaLatLng(12.932123492103944, 77.61748476788898)
val newEndPoint = OlaLatLng(12.933758797710456, 77.61836504365439)
bezierCurve.setPoints(newStartPoint, newEndPoint)
bezierCurve.setLineType(LineType.LINE_SOLID) // or LineType.LINE_DOTTED
8. Events and Methods
Zoom to location
To zoom the map to a specific location, use the zoomToLocation method.
val location = OlaLatLng(12.9715987, 77.594566)
val zoomLevel = 15.0olaMap.zoomToLocation(location, zoomLevel)
Get Current Location
To retrieve the user's current location, use the getCurrentLocation method. This method returns an OlaLatLng object representing the current location or null if the location is not available
val currentLocation: OlaLatLng? = olaMap?.getCurrentLocation()
if (currentLocation != null) {
// Use the current location} else {
// Handle the case where the location is not available}
Show Current Location
To display the user's current location on the map, use the showCurrentLocation method.
olaMap?.showCurrentLocation()
Hide Current Location
To hide the user's current location from the map, use the hideCurrentLocation method.
olaMap?.hideCurrentLocation()
9. Controls and Gestures
SDK allows you to customize the map's UI settings through the MapControlSettings object. You can enable or disable the following gestures and controls:
Rotate Gestures: Enable or disable the ability to rotate the map.
Scroll Gestures: Enable or disable the ability to scroll the map.
Zoom Gestures: Enable or disable the ability to zoom the map.
Tilt Gestures: Enable or disable the ability to tilt the map.
Double Tap Gestures: Enable or disable the ability to double tap the map.
Compass: Enable or disable the compass icon on the map.
To customize the UI settings, create a MapControlSettings object with the desired properties and pass it to the getMap method when initializing the map view.
SDK allows you to create a marker clustering that helps manage a large number of markers on a map by grouping them into clusters based on their proximity to each other. As the user zooms out, markers that are close together are combined into a single cluster marker. When zooming in, these clusters expand to show individual markers. This feature enhances the map's readability and performance, particularly when dealing with high marker densities.
Adding Clustered Markers Using FeatureCollection
To add clustered markers using a FeatureCollection, use the addClusteredMarkers method. This method takes in an OlaMarkerClusterOptions object and a FeatureCollection.
val featureCollection: FeatureCollection = // Initialize your feature collection hereval clusterOptions = OlaMarkerClusterOptions.Builder()
.setClusterRadius(50)
.setDefaultMarkerColor("#FF0000")
.setDefaultClusterColor("#00FF00")
.setDefaultMarkerIcon(bitmap)
.setTextSize(12f)
.setTextColor("#FFFFFF")
.build()
val clusteredMarkers = olaMap.addClusteredMarkers(clusterOptions, featureCollection)
Adding Clustered Markers Using FeatureCollection
To add clustered markers using a GeoJSON string, use the addClusteredMarkers method with the GeoJSON string as a parameter.
val geoJson: String = // Your GeoJSON string hereval clusterOptions = OlaMarkerClusterOptions.Builder()
.setClusterRadius(50)
.setDefaultMarkerColor("#FF0000")
.setDefaultClusterColor("#00FF00")
.setTextSize(12f)
.setTextColor("#FFFFFF")
.build()
val clusteredMarkers = olaMap?.addClusteredMarkers(clusterOptions, geoJson)
The OlaMarkerClusterOptions class allows you to customize the behavior and appearance of clustered markers. Below are the key properties you can set:
clusterRadius: The radius within which markers are grouped into clusters. (e.g., setClusterRadius(50))
defaultMarkerColor: The color of individual markers when they are not clustered. (e.g., setDefaultMarkerColor("#FF0000"))
defaultClusterColor: The color of the cluster marker. (e.g., setDefaultClusterColor("#00FF00"))
defaultMarkerIcon: A custom icon for individual markers. (e.g., setDefaultMarkerIcon(bitmap))
stop1Color, stop2Color: Stop colors 1 and 2 for the background of the clustered markers when zoomed out and the markers get merged into a cluster
textSize: The size of the text displayed on cluster markers. (e.g., setTextSize(12f))
textColor: The color of the text displayed on cluster markers. (e.g., setTextColor("#FFFFFF"))
Update Clustered Markers
You can update the existing clustered markers by providing a new FeatureCollection or GeoJSON string. You can also optionally pass a new OlaMarkerClusterOptions object to change the clustering settings.