Map Overlays¶
The Map SDK supports the following overlays using Annotations:
- Marker
- Polyline
- Polygon
Marker¶
A Marker is an annotation that displays an icon at a specific geographical location on the map. By default, a marker uses a predefined icon, but you can customize it by using the IconFactory to create an icon from any provided image. To add a marker, specify a LatLng position and call addMarker. Since the marker icon is centered on this position, it’s common to add padding around the image to align it visually as needed.
Markers are interactive by design — they respond to click events out of the box and are often paired with event listeners to show InfoWindows. An InfoWindow appears automatically when the marker has either a title or snippet assigned, providing additional context or details.
Add Marker¶
To add the marker with default icon
Kotlin¶
val marker = mapplsMap.addMarker(MarkerOptions().position(LatLng(latitude, longitude)))
Java¶
Marker marker = mapplsMap.addMarker(new MarkerOptions().position(LatLng(latitude, longitude)));
Add Marker with Infowindow¶
To add the marker with infowindow on click of marker
Kotlin¶
mapplsMap.addMarker(MarkerOptions().position(LatLng(latitude, longitude)).title("Title").snippet("Description"))
Java¶
mapplsMap.addMarker(new MarkerOptions().position(LatLng(latitude, longitude)).title("Title").snippet("Description"));
Custom Marker¶
To add the marker with custom Icon
Kotlin¶
mapplsMap.addMarker(MarkerOptions().position(LatLng(latitude, longitude)).icon(IconFactory.getInstance(context).fromResource(R.drawable.map_marker_icon)))
Java¶
mapplsMap.addMarker(new MarkerOptions().position(LatLng(latitude, longitude)).icon(IconFactory.getInstance(context).fromResource(R.drawable.map_marker_icon)));
Custom InfoWindow¶
To add custom Info window
Kotlin¶
mapplsMap.setInfoWindowAdapter(object: MapplsMap.InfoWindowAdapter {
override fun getInfoWindow(marker: Marker): View? {
val view: View? = getLayoutInflater().inflate(R.layout.layout, null)
val textView: TextView = view?.findViewById(R.id.text)!!
textView.text = marker.title
return view
}
})
Java¶
mapplsMap.setInfoWindowAdapter(new MapplsMap.InfoWindowAdapter() {
@Nullable
@Override
public View getInfoWindow(@NonNull Marker marker) {
View view = getLayoutInflater().inflate(R.layout.layout, null);
TextView text = view.findViewById(R.id.text);
text.setText(marker.getTitle());
return view;
}
});
Remove Marker¶
To remove the marker
Kotlin¶
mapplsMap.removeMarker(marker)
Java¶
mapplsMap.removeMarker(marker);
Polyline¶
A Polyline is a map feature that represents an open series of connected coordinates drawn as a continuous line.
Add polyline¶
To draw a polyline on Map
Kotlin¶
val polyline = mapplsMap.addPolyline(PolylineOptions()
.addAll(points)
.color(Color.parseColor("#3bb2d0"))
.width(2f))
Java¶
Polyline polyline = mapplsMap.addPolyline(new PolylineOptions()
.addAll(points)//list of LatLng
.color(Color.parseColor("#3bb2d0"))
.width(2));
Remove Polyline¶
To remove polyline from Map
Kotlin¶
mapplsMap.removePolyline(polyLine)
Java¶
mapplsMap.removePolyline(polyline);
Polygon¶
A Polygon is a closed shape formed by connecting a series of coordinates, creating a filled area on the map.
Add Polygon¶
To add a polygon on Map
Kotlin¶
val polygon = mapplsMap.addPolygon(PolygonOptions()
.addAll(polygon)
.fillColor(Color.parseColor("#3bb2d0")))
Java¶
Polygon polygon = mapplsMap.addPolygon(new PolygonOptions()
.addAll(polygon)//list of LatLng.
.fillColor(Color.parseColor("#3bb2d0")));
Remove Polygon¶
To remove a polygon
Kotlin¶
mapplsMap.removePolygon(polygon)
Java¶
mapplsMap.removePolygon(polygon);
Clear All Overlay¶
To clear all Marker
, Polyline
& Polygon
Kotlin¶
mapplsMap.clear()
Java¶
mapplsMap.clear();
For any queries and support, please contact:
Email us at apisupport@mappls.com
Support
Need support? contact us!