The MapmyIndiaDrivingRangePlugin allows you to plot driving range area to drive based on time or distance on MapmyIndia's vector map component.
The plugin offers the following basic functionalities:
- Get and Plot driving range as polygon on map.
- Update driving range on map.
- Clear already plotted driving range on map.
This can be done by following simple steps.
Follow these steps to add the SDK to your project –
- Create a new project in Android Studio
- Add MapmyIndia repository in your project level build.gradle
allprojects {
repositories {
maven {
url 'https://maven.mapmyindia.com/repository/mapmyindia/'
}
}
}
- Add below dependency in your app-level build.gradle
implementation 'com.mapmyindia.sdk:driving-range-plugin:0.0.1'
MapmyIndiaDrivingRangePlugin
is the main class which is required to be initialized to use different functionalities of plugin.
It allows you to plot driving range area based on time or distance.
MapmyIndiaDrivingRangePlugin mapmyIndiaDrivingRangePlugin = new MapmyIndiaDrivingRangePlugin(mapView, mMapmyIndiaMap);
var mapmyIndiaDrivingRangePlugin = MapmyIndiaDrivingRangePlugin(mapView, mMapmyIndiaMap)
A function drawDrivingRange
of instance of MapmyIndiaDrivingRangePlugin
will be used to get driving range and plot on map. This function will accept an instance of MapmyIndiaDrivingRangeOption
as request to get driving range.
Below is code for reference:
MapmyIndiaDrivingRangeContour rangeContour = MapmyIndiaDrivingRangeContour.builder()
.value(50)
.color("ff0000")
.build();
List<MapmyIndiaDrivingRangeContour> list = new ArrayList<>();
list.add(rangeContour);
MapmyIndiaDrivingRangeOption option = MapmyIndiaDrivingRangeOption.builder()
.location(location)
.rangeTypeInfo(
MapmyIndiaDrivingRangeTypeInfo.builder()
.rangeType(DrivingRangeCriteria.RANGE_TYPE_TIME)
.contours(list)
.build()
).build();
mapmyIndiaDrivingRangePlugin.drawDrivingRange(option)
//Or with callback
mapmyIndiaDrivingRangePlugin.drawDrivingRange(option, new IDrivingRangeListener() {
@Override
public void onSuccess() {
//Success
}
@Override
public void onFailure(int code, @NonNull String message) {
// Failure
}
});
val range = MapmyIndiaDrivingRangeContour.builder()
.value(50)
.color("ff0000")
.build();
val option = MapmyIndiaDrivingRangeOption.builder()
.location(location)
.rangeTypeInfo(
MapmyIndiaDrivingRangeTypeInfo.builder()
.rangeType(DrivingRangeCriteria.RANGE_TYPE_TIME)
.contours(listOf(range))
.build()
).build()
mapmyIndiaDrivingRangePlugin?.drawDrivingRange(option)
//OR with callback
mapmyIndiaDrivingRangePlugin?.drawDrivingRange(option, object :
IDrivingRangeListener {
override fun onSuccess() {
Toast.makeText(this@DrivingRangeActivity, "Success", Toast.LENGTH_SHORT).show()
}
override fun onFailure(code: Int, message: String) {
Toast.makeText(this@DrivingRangeActivity, message, Toast.LENGTH_SHORT).show()
}
})
MapmyIndiaDrivingRangeOptions
It is a structure that specifies the criteria for request for getting polygons as range to drive based on time or distance.
It contains following properties.
-
name[String]
: It is used for name of the driving range request. If name is specified, the name is returned with the response. -
location[Point](Mandatory)
: It is center point for range area that will surrounds the roads which can be reached from this point in specified time range(s). -
drivingProfile[String]
: Driving profile for routing engine. Default value isauto
. -
speedTypeInfo[MapmyIndiaDrivingRangeSpeed]
: It is used to calculate the polygon. Default value isMapmyIndiaDrivingRangeSpeed.optimal()
' -
rangeTypeInfo[MapmyIndiaDrivingRangeTypeInfo](Mandatory)
:- It is used to specify the type of range which is used to calculate the polygon. -
isForPolygons[Boolean]
: It is used to determine whether to return geojson polygons or linestrings. The default is true. -
showLocations[Boolean]
: It indicating whether the input locations should be returned as MultiPoint features. The default is false. It returns- one point feature for the exact input coordinates
- one point feature for the coordinates of the network node it snapped to.
-
denoise[Float]
: A floating point value from 0 to 1 (default of 1) which will be used to remove smaller contours. Default value is 0.5. -
generalize[Float]
: A floating point value in meters used as the tolerance for Douglas-Peucker generalization. Default value is 1.2
MapmyIndiaDrivingRangeTypeInfo
It contains following properties.
-
rangeType[String]
: It specify the type of range which is used to calculate the polygon. Possible values are:- DrivingRangeCriteria.RANGE_TYPE_TIME (Default): It means it takes time in min.
- DrivingRangeCriteria.RANGE_TYPE_DISTANCE: It means it takes distance in Km.
-
contours[List<MapmyIndiaDrivingRangeContour>]
: Each contour object is combination of value and colorHexString.
MapmyIndiaDrivingRangeContour
It contains following properties.
-
value(Integer)
: value taken as time or distance defined in instance ofMapmyIndiaDrivingRangeRangeTypeInfo
.- If type of range is time in minutes(default = 15, maximum = 80)
- If type of range is distance in kilometers(default = 1, maximum = 80)
-
color[String]
: It specify the color for the output of the contour. Pass a hex value, such asff0000
for red.
MapmyIndiaDrivingRangeOptimalSpeed
- For optimal Speed type.
MapmyIndiaDrivingRangeSpeed.optimal();
- For predictive speed type with current timestamp
MapmyIndiaDrivingRangeSpeed.predictiveSpeedFromCurrentTime();
- For predictive speed type with custom timestamp:
MapmyIndiaDrivingRangeSpeed.predictiveSpeedFromCustomTime(time)
We have provided some features with the plugin which will help to further enhance the experience.
To fit the bounds of the map for plotted driving range, user has to set camera.
mapmyIndiaDrivingRangePlugin.isSetMapBoundForDrivingRange(false);
mapmyIndiaDrivingRangePlugin?.isSetMapBoundForDrivingRange(false)
On setting it true
, plugin will set camera to fit bound. It's default value is true
.
Plotted driving range on Map can be removed by calling function clearDrivingRangeFromMap
.
Refer to the code below:
mapmyIndiaDrivingRangePlugin.clearDrivingRangeFromMap();
mapmyIndiaDrivingRangePlugin?.clearDrivingRangeFromMap()
For any queries and support, please contact:
Email us at [email protected]
Stack Overflow Ask a question under the mapmyindia-api
Support Need support? contact us!
Blog Read about the latest updates & customer stories
© Copyright 2022. CE Info Systems Ltd. All rights reserved. | Terms & Conditions