R
r3r3r3r
Guest
have an app where I plot to a map fragment data within a csv file stored in assets. The csv data is parsed and added to an arraylist, and plotted with a for loop to the fragment. The problem is that there are many clusters, and it looks cluttered.
How is it possible to use marker clustering on this data? From the guides I read I can only understand how to hardcode the LatLngs.
Any help would be greatly appreciated I'm a real beginner!
How is it possible to use marker clustering on this data? From the guides I read I can only understand how to hardcode the LatLngs.
Code:
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get a handle to the xml Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
LatLng Swansea = new LatLng(51.6167, -3.9500);
map.setMyLocationEnabled(true); // enables location indicator
map.moveCamera(CameraUpdateFactory.newLatLngZoom(S wansea, 11));
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(getAssets().open(
"data.csv")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<LatLng> latLngList = new ArrayList<LatLng>();
String line = "";
try {
while ((line = reader.readLine()) != null) // Read until end of file
{
double lat = Double.parseDouble(line.split(",")[0]); //parses the comma separated values
double lon = Double.parseDouble(line.split(",")[1]);
latLngList.add(new LatLng(lat, lon)); //adds to arraylist
}
} catch (NumberFormatException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Adds them to map
for (LatLng pos : latLngList) {
map.addMarker(new MarkerOptions().position(pos)
.icon(BitmapDescriptorFactory.fromResource(R.drawa ble.cctv))); //adds custom icon
}
Any help would be greatly appreciated I'm a real beginner!