package
com.gtappdevelopers.mapmyindia;
import
android.os.Bundle;
import
androidx.appcompat.app.AppCompatActivity;
import
com.mmi.LicenceManager;
import
com.mmi.MapView;
import
com.mmi.MapmyIndiaMapView;
import
com.mmi.layers.Marker;
import
com.mmi.layers.MarkerClusterer;
import
com.mmi.util.GeoPoint;
import
java.util.ArrayList;
public
class
MainActivity
extends
AppCompatActivity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LicenceManager.getInstance().setRestAPIKey(
"Enter your API key"
);
LicenceManager.getInstance().setMapSDKKey(
"Enter your API key"
);
MapmyIndiaMapView mapmyIndiaMapView = findViewById(R.id.idMapView);
MapView mapView = mapmyIndiaMapView.getMapView();
ArrayList<MarkerModel> markerModels =
new
ArrayList<>();
markerModels.add(
new
MarkerModel(
"Location 1"
,
new
GeoPoint(
28.549356
,
77.26780099999999
)));
markerModels.add(
new
MarkerModel(
"Location 2"
,
new
GeoPoint(
28.551844
,
77.26749
)));
markerModels.add(
new
MarkerModel(
"Location 3"
,
new
GeoPoint(
28.554454
,
77.265473
)));
markerModels.add(
new
MarkerModel(
"Location 4"
,
new
GeoPoint(
28.549637999999998
,
77.262909
)));
markerModels.add(
new
MarkerModel(
"Location 5"
,
new
GeoPoint(
28.555245
,
77.266117
)));
markerModels.add(
new
MarkerModel(
"Location 6"
,
new
GeoPoint(
28.558149
,
77.269787
)));
MarkerClusterer markerClusterer =
new
MarkerClusterer(
this
);
markerClusterer.setColor(getResources().getColor(R.color.purple_200));
markerClusterer.mAnchorV = Marker.ANCHOR_CENTER;
markerClusterer.mTextAnchorV = Marker.ANCHOR_CENTER;
markerClusterer.setTextSize(
12
);
ArrayList<GeoPoint> points =
new
ArrayList<>();
for
(MarkerModel markerModel : markerModels) {
Marker marker =
new
Marker(mapView);
marker.setTitle(markerModel.getTitle());
marker.setPosition(markerModel.getGeoPoint());
marker.setRelatedObject(markerModel);
markerClusterer.add(marker);
points.add(markerModel.getGeoPoint());
}
mapView.setBounds(points);
mapView.getOverlays().add(markerClusterer);
mapView.invalidate();
}
}