Reputation: 1362
I have an ArrayList> called coordinates which has 3 lists: one with a variable called hr, one with the latitude and one with the longitude. In each of these there are thousands of entries. My idea was to map all this variables in a map (lol) where a dot of a color (depending on hr) was placed in the position specified by the latitude and logitude. This is how I am currently doing it. I have a standard activity with google maps. At the end of the onCreate I call:
paint()
What this function does:
/*Paint the dots of locations*/
private void paint (){
//Paint the city with the blood of my enemies
ArrayList<ArrayList<String>> coordinates = new ArrayList<ArrayList<String>>();
ArrayList<String> lat = new ArrayList<String>();
ArrayList<String> lon = new ArrayList<String>();
ArrayList<String> hr = new ArrayList<String>();
coordinates = readfile(); #Import file from downloads and process it, takes 0.5sec for over 6000 entries.
/*Here and down takes 1 minute for the same number of entries*/
lat = coordinates.get(0);
lon = coordinates.get(1);
hr = coordinates.get(2);
for (int i = 0; i < lat.size(); i++) {
//paint
// Add a circle for high heart rate
if(Integer.parseInt(hr.get(i))>100){
Circle circle = mMap.addCircle(new CircleOptions()
.center(new LatLng(Double.parseDouble(lat.get(i)), Double.parseDouble(lon.get(i))))
.radius(10) //size of circle
.strokeColor(Color.RED)
.fillColor(Color.RED));
}
else{
Circle circle = mMap.addCircle(new CircleOptions()
.center(new LatLng(Double.parseDouble(lat.get(i)), Double.parseDouble(lon.get(i))))
.radius(10) //size of circle
.strokeColor(Color.GREEN)
.fillColor(Color.GREEN));
}
}
}
I added some logs to check the times, and the importing and processing of the file takes 0.5 seconds. The rest takes 1 minute.
What would be a way of optimizing this? The idea I had was if it was possible to take all the spots that are repeated (same latitude and longitude) and use either the most common hr value or the average(?). I don't know how much this would help though if the user is on the move.
Any suggestions?
Upvotes: 0
Views: 68
Reputation: 1355
Test data:
1:1, 1:2, 3:4, 2:3, 5:5
Not very clear what to do without your domain. The standard solution to this situation is the omnibus multiple markers in a large one. Etc =>
1:1.5, 2.5:3.5, 5:5
Also, I do not see you limit the visibility zone. Do I have to show you everything? If you see only 0:0 to 2:2, you need to visible only:
1:1, 1:2
Upvotes: 1
Reputation: 5314
These simple things come to mind.
Initialize your ArrayLists
with initial capacity to reduce its resize (this is somewhat a heavy task) by doing something like below. I don't know the code for readFile()
so do that yourself.
ArrayList<String> lat = new ArrayList<String>(6000);
Do not put lat.size()
in the for
condition.
for (int i = 0; i < lat.size(); i++) {
Why maintain 3 List
? I don't know the specific requirements but if my assumption is correct, you could do something like ArrayList<MyCustomObjectWhichHoldsTheThreeValuesInOneClass>
Upvotes: 3