Map SDK - Android
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.
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
- Add SDK Dependency
- Define view in xml
- Map view initialization
You have to download the Android Map SDK from the link Android Map SDK and copy it to libs folder.
Include the SDK in your project by adding the following dependencies to your build.gradle
Include below code in your xml file where you want to load a map
Initialize the map in your activity or fragment:
Features
- Dynamic maps
- Markers
- Infowindows
- Polyline
- Circle
- Polygon
- Bezier Curve
- Events and Methods
- Controls and Gestures
- Marker Clustering
1. Dynamic Map
The Dynamic Map provides a comprehensive solution for integrating interactive map functionalities into your application.
SDK supports dynamic maps with various interactive features:
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.
- Updating a Marker To update the an existing marker, use the appropriate method on the marker object.
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.
- 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.
- Updating an Info Window To update the text in an existing info window, use the updateInfoWindow method on the marker object.
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.
- 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.
- Updating Polyline To update other properties of an existing polyline, use the respective methods on the polyline object.
5. Circle
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.
- 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.
- Updating a Circle To update other properties of an existing circle, use the respective methods on the circle object.
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.
- 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.
- Updating a Polygon To update other properties of an existing polygon, use the respective methods on the polygon object.
7. Bezier Curve
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.
- 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.
- Updating a Bezier Curve To update other properties of an existing Bezier Curve, use the respective methods on the Bezier Curve object.
8. Events and Methods
- Zoom to location To zoom the map to a specific location, use the zoomToLocation method.
- 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
- Show Current Location To display the user's current location on the map, use the showCurrentLocation method.
- Hide Current Location To hide the user's current location from the map, use the hideCurrentLocation method.
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.
10. Marker Clustering
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.
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.
- Adding Clustered Markers Using FeatureCollection To add clustered markers using a GeoJSON string, use the addClusteredMarkers method with the GeoJSON string as a parameter.
- 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.
- Remove Clustered Markers To remove the clustered markers from the map, use the removeClusteredMarkers method.
This method takes in an OlaMarkerClusterOptions object and a FeatureCollection.
- The OlaMarkerClusterOptions class allows you to customize the behavior and appearance of clustered markers. Below are the key properties you can set:
You can also optionally pass a new OlaMarkerClusterOptions object to change the clustering settings.