0

My app has a basic Google Maps activity, and on the map there is 4 markers which display some text. These markers are displayed on the map using a HashMap.

This is some of the code at the moment -

Double waterPrice = 1.38;
Double foodPrice = 1.23;

mMyMarkersArray.add(new MyMarkers("Tesco", "Tesco", Double.parseDouble("1.1111"), Double.parseDouble("-1.1111"), "Water: €" + waterPrice , "Food: €" + foodPrice , "Address: London"));
mMyMarkersArray.add(new MyMarkers("Sainsburys", "Sainsburys", Double.parseDouble("1.1111"), Double.parseDouble("-1.1111"), "Water: €" +waterPrice , "Food: €" + foodPrice , "Address: Manchester"));

I was wondering, would it be possible to define an array with 5 values such as:

[1.33, 1.23, 1.24, 1.99, 2.01];

And then when the map is loaded first, it takes the value at index 0, assigns it to waterPrice, and then after I click a button or after 5 seconds has passed, it moves on to index 1, index 2 etc and sending this new price to the marker each the time button is clicked. So instead of having my waterPrice and foodPrice defined above, I can just iterate through the array, and send the value to the marker.

Could I use two arrays, one for waterPrice and one for foodPrice so that I can assign waterPrice to index 0 in the array?

Sorry if what I am trying to explain is not really clear, if anyone could help me I would appreciate it. I'm stuck at the moment trying to come up with a way to implement this.

funky
  • 131
  • 1
  • 1
  • 6

1 Answers1

1

I don't understand very well what you are trying to do, so if my answer is wrong please give more details. If your problem is only with running code after some delay, you could use a Handler to run code after a specific time. Something like this:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    // run after one second
  }
}, 1000);

If you have a list with the defined times and prices:

for (int i=0; i<timeList.size(); i++) {
    Double time = timeList.get(i);
    Double waterPrice = waterPriceList.get(i);
    Double foodPrice = foodPriceList.get(i);
            handler.postDelayed(new Runnable() {
          @Override
          public void run() {
            // update your marker
          }
        }, timeInSeconds*1000);
}
allo86
  • 946
  • 1
  • 9
  • 23
  • Sorry @allo86, I'm not sure if I explained it clearly enough. I basically have 4 markers on my map, at the moment when they are clicked on, they display the text "Food: ", what I am trying to do is have an array of prices like I listed in my original post, and every 5 seconds, the next value in the array will be displayed in the marker. I updated my OP, hopefully it is a bit clearer. – funky Sep 28 '15 at 20:51
  • do you want de list of prices as if a pin icon ? or show the list item by item in the infowindow of the marker ? – brayan camilo villate leon Sep 28 '15 at 21:21
  • @brayancamilovillateleon I have my information appearing in a pin icon, I want to show `waterPrice` and `foodPrice` in one pin icon – funky Sep 29 '15 at 19:03
  • do you want some like this http://stackoverflow.com/questions/14811579/android-map-api-v2-custom-marker-with-imageview but instead of photo you set de info at price off your food – brayan camilo villate leon Sep 30 '15 at 16:40