How can inflate addmarker from Cursor SQLITE? - android

Im try inflate follow these example
public void onMapReady(GoogleMap googleMap) {
cursor = mb.listar();
mMap = googleMap;
// Add a marker in Sydney and move the camera
//LatLng sydney = new LatLng(-34, 151);
// mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
//mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
And my methods are
CajeroDAO
public Cursor getAll() throws SQLException {
Cursor c = MiBD.getDB().query(true, CAJEROS_TABLE, CAMPOS_CAJEROS, null, null, null, null, null, null);
return c;
}
And
MiCajeroOperacional
public Cursor listar() {
return cajero.getAll();
}
Then, as I add cursor marks for each of them?
Solution for my problem
Here post my solution for center and add markers from cursor, is easy quick solution.
#Override
public void onMapReady(GoogleMap googleMap) {
cursor = mb.listar();
mMap = googleMap;
LatLng mark = null;
List<Marker> markersList = new ArrayList<Marker>();
int i = 0;
while (cursor.moveToNext()) {
double lat = cursor.getDouble(cursor.getColumnIndex("lat"));
double lng = cursor.getDouble(cursor.getColumnIndex("lng"));
mark = new LatLng(lat, lng);
Marker markCajero = mMap.addMarker(new MarkerOptions().position(mark).title("Sucursal NÂș" + i).snippet(cursor.getString(cursor.getColumnIndex("direccion"))));
// mMap.moveCamera(CameraUpdateFactory.newLatLng(mark), 15);
markersList.add(markCajero);
i++;
}
cursor.close();
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
int padding = 50;
LatLngBounds bounds = builder.build();
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mMap.moveCamera(cu);
}

Related

How to output markers from SQLite database to MapView and Google Map

I have set my code out so when the user moves to the map fragment it shows a map with all the markers in the database. I have two dummy markers and they work, but thew ones from my database dont show.
I have made sure the SQL query is correct and have tried adding static markers, but the dynamic ones dont show up.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.map,container,false);
mapView = (MapView) rootView.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap googleMap) {
Log.i("DEBUG", "onMapReady");
map = googleMap;
LatLng sydney = new LatLng(-34, 151);
LatLng paris = new LatLng(12,-40);
map.addMarker(new
MarkerOptions().position(sydney).title("Marker in Sydney"));
map.addMarker(new
MarkerOptions().position(paris).title("Marker in Ocean"));
try {
String sql = "SELECT
marker.markerLat,marker.markerLon,marker.markerDate
FROM marker LEFT JOIN tripMarker ON" +
" marker.markerID = tripMarker.markerID LEFT
JOIN userTrip ON userTrip.tripID =
tripMarker.tripID " +
"WHERE userTrip.userID = '" + User.UserLoggedOn
+ "';";
Cursor cursor = db.rawQuery(sql, null);
if ( cursor.moveToFirst() ) {
while (cursor.moveToNext()) {
double lat =
cursor.getDouble(cursor.getColumnIndex("markerLat"));
System.out.println(lat);
double lon =
cursor.getDouble(cursor.getColumnIndex("markerLon"));
System.out.println(lon);
LatLng latLng = new LatLng(lat, lon);
MarkerOptions markerOptions = new
MarkerOptions();
markerOptions.position(latLng);
map.addMarker(markerOptions.title(cursor.getString(
cursor.getColumnIndex("markerDate"))));
}
}
}catch (Exception e){
e.printStackTrace();
}
}
});
return rootView;
}
Here is my fragment XML
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
Should you be skipping the first row? Is it the only row that would be returned?
Perhaps the reason why logging doesn't work as per the comment :-
for some reason, I have put logs in the if statement and in the
catch, but I cant seem to find them. Does that mean they both dont
trigger?
Perhaps you should try (removing the if (csr.moveToFirst()) which will skip the first row) by using :-
MarkerOptions().position(paris).title("Marker in Ocean"));
try {
String sql = "SELECT
marker.markerLat,marker.markerLon,marker.markerDate
FROM marker LEFT JOIN tripMarker ON" +
" marker.markerID = tripMarker.markerID LEFT
JOIN userTrip ON userTrip.tripID =
tripMarker.tripID " +
"WHERE userTrip.userID = '" + User.UserLoggedOn
+ "';";
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
double lat =
cursor.getDouble(cursor.getColumnIndex("markerLat"));
System.out.println(lat);
double lon =
cursor.getDouble(cursor.getColumnIndex("markerLon"));
System.out.println(lon);
LatLng latLng = new LatLng(lat, lon);
MarkerOptions markerOptions = new
MarkerOptions();
markerOptions.position(latLng);
map.addMarker(markerOptions.title(cursor.getString(
cursor.getColumnIndex("markerDate"))));
}
}catch (Exception e){
e.printStackTrace();
}
I would also drop wrapping the code in a try/catch clause you may well be hiding issues.

java.lang.IllegalStateException: no included points in fragment in android

In my fragment i get error java.lang.IllegalStateException: no included points = =
i try many solution but not work
Here is my code:
public void mSetUpMap() {
/**clear the map before redraw to them*/
googleMap.clear();
/**Create dummy Markers List*/
if (AppUtil.itinerary != null)
str = AppUtil.itinerary.getItinerary();
if (AppUtil.itinerary != null)
shareUrl = AppUtil.itinerary.getShareUrl();
Log.e("Ittt", "" + AppUtil.itinerary.getItinerary());
((HomeActivity) getActivity()).setTexrViewText(str);
poiList.clear();
poiList = AppUtil.itinerary.getPoiList();
final List<Marker> markersList = new ArrayList<>();
for (POI item : poiList) {
Marker m1 = googleMap.addMarker(new MarkerOptions().position(new
LatLng(item.getLatitude(),
item.getLongitude()))
.title(item.getName()).anchor(0.7f, 0.6f)
.icon(BitmapDescriptorFactory.fromBitmap(getCustomMarker
((R.drawable.m2red),
item.getName()))));
markersList.add(m1);
}
builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
/**initialize the padding for map boundary*/
int padding = 200;
/**create the bounds from latlngBuilder to set into map camera*/
LatLngBounds bounds = builder.build();
/**create the camera with bounds and padding to set into map*/
cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
/**call the map call back to know map is loaded or not*/
googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
#Override
public void onMapLoaded() {
/**set animated zoom camera into map*/
googleMap.animateCamera(cu);
PolylineOptions polylineOptions = new PolylineOptions();
for (POI item : poiList) {
polylineOptions.add(new LatLng(item.getLatitude(),
item.getLongitude()));
}
polylineOptions.width(5);
polylineOptions.getPoints();
polylineOptions.color(getResources().getColor(R.color.red));
googleMap.addPolyline(polylineOptions);
polylineOptions.geodesic(true);
if (!poiList.isEmpty()) {
// Adjusting Bounds
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate mCameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, 2);
googleMap.animateCamera(mCameraUpdate);
}
}
});
googleMap.setOnMarkerClickListener(new
GoogleMap.OnMarkerClickListener()
{
#Override
public boolean onMarkerClick(final Marker marker) {
ValueAnimator ani = ValueAnimator.ofFloat(0, 1); //change for
(0,1) if you want a fade in
ani.setDuration(2000);
ani.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
#Override
public void onAnimationUpdate(ValueAnimator animation) {
marker.setAlpha((float) animation.getAnimatedValue());
}
});
ani.start();
if (marker.getTitle().equals(poiList.get(0).getName())) {
AppUtil.poi = poiList.get(0);
name = poiList.get(0).getName();
img = poiList.get(0).getImage();
lat = poiList.get(0).getLatitude();
lon = poiList.get(0).getLongitude();
showPoi(name, img, lat, lon);
} else if (marker.getTitle().equals(poiList.get(1).getName())) {
AppUtil.poi = poiList.get(1);
name = poiList.get(1).getName();
img = poiList.get(1).getImage();
lat = poiList.get(1).getLatitude();
lon = poiList.get(1).getLongitude();
showPoi(name, img, lat, lon);
} else if (marker.getTitle().equals(poiList.get(2).getName())) {
AppUtil.poi = poiList.get(2);
name = poiList.get(2).getName();
img = poiList.get(2).getImage();
lat = poiList.get(2).getLatitude();
lon = poiList.get(2).getLongitude();
showPoi(name, img, lat, lon);
}
return true;
}
});
}
I get error LatLngBounds bounds = builder.build();
this line
first time fragment work perfect but when i pressed back button and try to get this fragment i get this error
My Logcat Show:
java.lang.IllegalStateException: no included points
at com.google.android.gms.common.internal.zzac.zza(Unknown Source:8)
at com.google.android.gms.maps.model.LatLngBounds$Builder.build(Unknown
Source:10)
at
info.ernica.fragment.ItinerarioFragment.mSetUpMap
(ItinerarioFragment.java:455)
at info.ernica.fragment.ItinerarioFragment$2.onMapReady
(ItinerarioFragment.java:205)
at com.google.android.gms.maps.MapFragment$zza$1.zza(Unknown Source:7)
at com.google.android.gms.maps.internal.zzt$zza.onTransact(Unknown
Source:32)
at android.os.Binder.transact(Binder.java:612)
at fg.b(:com.google.android.gms.dynamite_mapsdynamite#13280051#13.2.80
(040408-211705629):19)
at
com.google.android.gms.maps.internal.bg.a
(:com.google.android.gms.dynamite_mapsdynamite#13280051#13.2.80 (040408-
211705629):5)
at com.google.maps.api.android.lib6.impl.be.run
(:com.google.android.gms.dynamite_mapsdynamite#13280051#13.2.80 (040408-
211705629):5)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Instead of checking whether poiList is empty, you need to check if markersList is empty in the setOnMapLoadedCallback method.
if (!markersList.isEmpty()) {
// Adjusting Bounds
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate mCameraUpdate =
CameraUpdateFactory.newLatLngBounds(bounds, 2);
googleMap.animateCamera(mCameraUpdate);
}
From the error it looks like your markersList is empty. It needs to contain at least one point for LatLngBounds.Builder to work properly.

Android. Google map. How to draw polygon from array

I m new to android app development.
I have WKT (POLYGON)
How to draw polygon on google map from wkt?
I try
String str;
ArrayList<String> coordinates = new ArrayList<String>();
str = tvwkt.getText().toString();
str = str.replaceAll("\\(", "");
str = str.replaceAll("\\)", "");
str = str.replaceAll("POLYGON", "");
str = str.replaceAll("POINT", "");
str = str.replaceAll(", ", ",");
str = str.replaceAll(" ", ",");
str = str.replaceAll(",,", ",");
String[] commatokens = str.split(",");
for (String commatoken : commatokens) {
coordinates.add(commatoken);
}
for (int i = 0; i < coordinates.size(); i++) {
String[] tokens = coordinates.get(i).split("\\s");
for (String token : tokens) {
listPoints.add(token);
}
}
PolygonOptions rectOptions = new PolygonOptions().addAll(listPoints).strokeColor(Color.BLUE).fillColor(Color.CYAN).strokeWidth(7);
polygon = mMap.addPolygon(rectOptions);
But its not work.
Hepl me please.
thanks.
This is a better aproach, for this sample WKT Polygon:
wkt = "POLYGON((-84.22800686845923 40.137783757219864,-82.71787050257508 33.66027041269767,-78.6190283330219 37.694486391034445,-84.22800686845923 40.137783757219864))";
We need to get the negative values, and also order correctly the lat/long
private LatLng[] getPolygonPoints() {
ArrayList<LatLng> points = new ArrayList<LatLng>();
Pattern p = Pattern.compile("(\\d*\\.\\d+)\\s(\\d*\\.\\d+)");
Matcher m = p.matcher(wkt);
String point;
while (m.find()) {
point = wkt.substring(m.start() - 1, m.end());
points.add(new LatLng(Double.parseDouble(point.split(" ")[1]), Double.parseDouble(point.split(" ")[0])));
}
return points.toArray(new LatLng[points.size()]);
}
And then draw the polygon like the last response:
public void drawPolygon() {
LatLng[] points = getPolygonPoints();
Polygon p = mMap.addPolygon(
new PolygonOptions()
.add(points)
.strokeWidth(7)
.fillColor(Color.CYAN)
.strokeColor(Color.BLUE)
);
//Calculate the markers to get their position
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (LatLng point : points) {
b.include(point);
}
LatLngBounds bounds = b.build();
//Change the padding as per needed
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20, 20, 5);
mMap.animateCamera(cu);
}
I can do it.
Read LatLong from WKT and add to Array
private LatLng[] GetPolygonPoints(String polygonWkt) {
Bundle bundle = getIntent().getExtras();
wkt = bundle.getString("wkt");
ArrayList<LatLng> points = new ArrayList<LatLng>();
Pattern p = Pattern.compile("(\\d*\\.\\d+)\\s(\\d*\\.\\d+)");
Matcher m = p.matcher(wkt);
String point;
while (m.find()){
point = wkt.substring(m.start(), m.end());
points.add(new LatLng(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2))));
}
return points.toArray(new LatLng[points.size()]);
}
then draw polygon
public void Draw_Polygon() {
LatLng[] points = GetPolygonPoints(polygonWkt);
Polygon p = mMap.addPolygon(
new PolygonOptions()
.add(points)
.strokeWidth(7)
.fillColor(Color.CYAN)
.strokeColor(Color.BLUE)
);
//Calculate the markers to get their position
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (LatLng point : points) {
b.include(point);
}
LatLngBounds bounds = b.build();
//Change the padding as per needed
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 20,20,5);
mMap.animateCamera(cu);
}
finally
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(MAP_TYPE_HYBRID);
mMap.getUiSettings().setRotateGesturesEnabled(false);
mMap.getUiSettings().setMapToolbarEnabled(false);
LatLng[] points = GetPolygonPoints(polygonWkt);
if (points.length >3){
Draw_Polygon();
}
else {
Add_Markers();
}
}

Android - Cursor onMapReady (Markers)

I'm trying to "inflate" my content from SQLite into Markers but the solution I took of here it's not working, and it's not throwing any information on Log.
I'm a bit new on this Marker stuff and SQLite
My code inside the Fragment:
SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
pds = new ParksDataSource(dbHelper.db);
parks = pds.getAllParks();
List<Marker> markersList = new ArrayList<Marker>();
int i = 0;
Cursor cursor = db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
null);
try {
while (cursor.moveToNext()) {
String[] latlong = cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_COORDINATES)).split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
mark = new LatLng(latitude, longitude);
Marker mPark = mMap.addMarker(new MarkerOptions().position(mark)
.title(cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)))
.icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.mipmap.ic_pin, cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_FREE))))));
mPark.setTag(0);
markersList.add(mPark);
Log.d("HierParks", "Pin: " + i + ", " + latitude + "," + longitude + " - Park:" + cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)));
i++;
}
} finally {
cursor.close();
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}`
Thank you for your time.
Finally I managed to fix it, hope this help someone.
My ParkDataSource:
public Cursor getAll() {
return db.rawQuery("SELECT * FROM " + SQLiteHelper.TABLE_PARKS,
null);
}
My Fragment:
SQLiteHelper dbHelper = new SQLiteHelper(getActivity());
pds = new ParksDataSource(dbHelper.db);
cursor = pds.getAll();
List<Marker> markersList = new ArrayList<Marker>();
int i = 0;
try {
while (cursor.moveToNext()) {
String[] latlong = cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_COORDINATES)).split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
mark = new LatLng(latitude, longitude);
if (cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_SLOTS)) == null){
Marker mPark = map.addMarker(new MarkerOptions().position(mark)
.title(cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_TITLE)))
.icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.mipmap.ic_pin, cursor.getString(cursor.getColumnIndex(SQLiteHelper.COL_PARKS_FREE))))));
mPark.setTag(0);
markersList.add(mPark);
}
i++;
}
} finally {
cursor.close();
}
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Marker m : markersList) {
builder.include(m.getPosition());
}

Cluster Marker miscalculating when zoom out Android google maps

I'm trying to implement a cluster marker on my map, and it is behaving a little strange, first, it shows me the cluster marker with the right number of markers, but when I zoom out to join other markers it generates another cluster marker which I don't know where it is coming from and why it is showing on the map, I`ll add some image to explain it better:
Here is the image with zoom in, as you can see, I have a cluster marker with 8 points and another one alone, so when I zoom out it should give me one clusterMarker with 9 points, but look what happens when I zoom out:
What that cluster marker with 7 points is doing there?
here is my code:
public class MapaViagem extends FragmentActivity implements ClusterManager.OnClusterClickListener<MyItem>, ClusterManager.OnClusterItemClickListener<MyItem> {
private GoogleMap googleMap;
private String rm_IdViagem;
private List<ClienteModel> mClienteModel = new ArrayList<ClienteModel>();
private List<EnderecoModel> mEnderecoModel = new ArrayList<EnderecoModel>();
private ArrayList<LatLng> coordList = new ArrayList<LatLng>();
private ArrayList<String> nomes = new ArrayList<String>();
private ViagemModel mViagemModel = new ViagemModel();
private ClusterManager<MyItem> mClusterManager;
private ProgressDialog dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
try {
Bundle parametros = getIntent().getExtras();
rm_IdViagem = parametros.getString("id_viagem");
Repositorio ca = new Repositorio(this);
mViagemModel = ca.getViagemPorId(Integer.valueOf(rm_IdViagem));
Repositorio cl = new Repositorio(this);
mClienteModel = cl.getClientesViagem(Integer.valueOf(rm_IdViagem));
String waypoints = "waypoints=optimize:true";
String coordenadas = "";
if(mClienteModel != null) {
for (int i = 0; i < mClienteModel.size(); i++) {
Repositorio mRepositorio = new Repositorio(this);
mEnderecoModel = mRepositorio.getListaEnderecosDoCliente(Integer.valueOf(mClienteModel.get(i).getClientes_id()));
for (int j = 0; j < mEnderecoModel.size(); j++) {
// Loading map
initilizeMap();
// Changing map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
// googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);
// Showing / hiding your current location
googleMap.setMyLocationEnabled(true);
// Enable / Disable zooming controls
googleMap.getUiSettings().setZoomControlsEnabled(true);
// Enable / Disable my location button
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
// Enable / Disable Compass icon
googleMap.getUiSettings().setCompassEnabled(true);
// Enable / Disable Rotate gesture
googleMap.getUiSettings().setRotateGesturesEnabled(true);
// Enable / Disable zooming functionality
googleMap.getUiSettings().setZoomGesturesEnabled(true);
float latitude = Float.parseFloat(mEnderecoModel.get(j).getLatitude());
float longitude = Float.parseFloat(mEnderecoModel.get(j).getLongitude());
coordenadas += "|" + latitude + "," + longitude;
nomes.add(mClienteModel.get(i).getNome());
coordList.add(new LatLng(latitude, longitude));
mClusterManager = new ClusterManager<MyItem>(MapaViagem.this, googleMap);
mClusterManager.setRenderer(new MyClusterRenderer(MapaViagem.this, googleMap, mClusterManager));
addItems(coordList, nomes);
googleMap.setOnCameraChangeListener(mClusterManager);
googleMap.setOnMarkerClickListener(mClusterManager);
mClusterManager.setOnClusterClickListener(this);
mClusterManager.setOnClusterItemClickListener(this);
mClusterManager.cluster();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 5));
}
}
String sensor = "sensor=false";
String params = waypoints + coordenadas + "&" + sensor;
String output = "json";
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + params;
ReadTask downloadTask = new ReadTask();
downloadTask.execute(url);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
#Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(item, markerOptions);
markerOptions.title(String.valueOf(item.getName()));
}
#Override
protected void onClusterItemRendered(MyItem clusterItem, Marker marker) {
super.onClusterItemRendered(clusterItem, marker);
//here you have access to the marker itself
}
#Override
protected boolean shouldRenderAsCluster(Cluster<MyItem> cluster) {
return cluster.getSize() > 1;
}
}
}
There seems to be an issue in this code:
coordenadas += "|" + latitude + "," + longitude; nomes.add(mClienteModel.get(i).getNome());
coordList.add(new LatLng(latitude, longitude));
mClusterManager = new ClusterManager<MyItem>(MapaViagem.this, googleMap);
mClusterManager.setRenderer(new MyClusterRenderer(MapaViagem.this, googleMap, mClusterManager));
addItems(coordList, nomes);
You should be adding these two things in there:
getMap().setOnCameraChangeListener(mClusterManager);
and
private void addItems() {
// Set some lat/lng coordinates to start with.
double lat = 51.5145160;
double lng = -0.1270060;
// Add ten cluster items in close proximity, for purposes of this example.
for (int i = 0; i < 10; i++) {
double offset = i / 60d;
lat = lat + offset;
lng = lng + offset;
MyItem offsetItem = new MyItem(lat, lng);
mClusterManager.addItem(offsetItem);
}
Here's an example from the documentation: https://developers.google.com/maps/documentation/android/utility/marker-clustering#simple

Categories

Resources