A Google Maps Android library to render marker clusters as charts categorized on the Google Maps Android with specified values.
Available Charts: Pie Chart, Bar Chart and Donut Chart
- Make sure you have JCenter in your repository list:
repositories {
jcenter()
}
- Add a dependency to your build.gradle:
dependencies {
implementation 'com.aminyazdanpanah:google-maps-android-charts:1.3'
}
This library is a wrapper around "Google Maps Android API utility library" and renderer marker cluster as charts on th Google Maps. You need to implement com.google.maps.android:android-maps-utils:0.5+
and com.google.android.gms:play-services-maps:16.1.0
in your build.gradle dependencies.
-
NOTE: Before using this library, please read the "Google Maps Android API utility library documentation" .
-
NOTE: Before Building the demo, you must get an API key which you can then add to your demo app.
First, you need to generate markers that have a name.
You must initialize CMaker
class that is implemented by ClusterItem
and pass the LarLng, the name of marker and the drawable Id. Also you can set the title and snippet of the marker.
CMarker marker = new CMarker(new LatLng(52.22222, 36.25622), "Ford", R.drawable.marker_red); //(Location of marker, specifed name, the drawable marker ID)
marker.setTitle("somthing you want to display when you tap on marker");
CMarker marker2 = new CMarker(new LatLng(52.25552, 36.25624), "Toyota", R.drawable.marker_green); //(Location of marker, specifed name, the drawable marker ID)
marker.setTitle("somthing you want to display when you tap on marker");
//...
Add the marker to the addItem()
method;
clusterManager.addItem(marker);
clusterManager.addItem(marker2);
//...
This library uses the the name to calculate the values of charts. In face, the number of each slice of chart is sum of marker's name. Also you must set the names of markers and the colors you would like to render. The length of names array must be the same as length of colors array.
String[] names = {"Toyota", "Ford", "Honda", "Dodge"};
int[] colors = {Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW};
PieChartRenderer chart = new PieChartRenderer(getApplicationContext(), googleMap, clusterManager);
chart.colors(colors);
chart.names(names);
BarChartRenderer chart = new BarChartRenderer(getApplicationContext(), googleMap, clusterManager);
chart.colors(colors);
chart.names(names);
DonutChartRenderer chart = new DonutChartRenderer(getApplicationContext(), googleMap, clusterManager);
chart.colors(colors);
chart.names(names);
At the end, you must pass chart
object to setRenderer
method in ClusterManager
class:
clusterManager.setRenderer(chart);
You can customize the values of chart by extending ChartRenderer
class and override the values
method:
class customPieChartRenderer extends PieChartRenderer {
@Override
float[] values(Cluster<CMarker> cluster){
// Return any value
}
}
I'd love your help in improving, correcting, adding to the specification. Please file an issue or submit a pull request.
Please see Contributing File for more information.
If you discover a security vulnerability within this package, please send an e-mail to Amin Yazdanpanah via: contact [AT] aminyazdanpanah • com.
Copyright 2019 Amin Yazdanpanah<www.aminyazdanpanah.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.