0

I am fairly new to app development, specifically Android. I have a CSV file with each line containing a pair of lat's and long's and a name for the POI. With my code below, after much reading and examining sample codes, I have successfully plotted the points on the map. However, I do not know how to add the title (name of POI) portion for the marker options section. My code below does not add the title on each POI. Any assistance will be highly appreciated:

Each line of the CSV file looks like this : PlaceName,-29.231,130.342.

InputStreamReader is = new InputStreamReader(getAssets().open("test.csv"));
        BufferedReader reader = new BufferedReader(is);

        List<LatLng> latLngList = new ArrayList<LatLng>();
        List<String> siteList = new ArrayList<String>();


        String info = "";
        while ((info = reader.readLine()) != null) {
            String[] line = info.split(",");

            latitude = Double.parseDouble(line[1]);
            longitude = Double.parseDouble(line[2]);
            siteName = String.valueOf(line[0]);
            latLngList.add(new LatLng(latitude, longitude));
            siteList.add(new String(siteName));
        }

       for  (LatLng towerLatLong : latLngList){
           positionSite(towerLatLong,siteName);
       }
        for  (String siteName : siteList) {
            positionSite(towerLatLong, siteName);
        }



    }
    catch (Exception e){
    }

    }

public void positionSite(LatLng towerLatLong, String siteName) {
    MarkerOptions options = new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromAsset("ctower1.png"))
            .title(siteName)
            .position(towerLatLong);


    mMap.addMarker(options);

}
Avi909gp
  • 13
  • 4

1 Answers1

0

The title will be revealed when you click the marker :) Try the answer here https://stackoverflow.com/a/14588548/8160990

Tudor Lozba
  • 736
  • 1
  • 6
  • 9
  • Thanks, that part I know :). I want to add a title for each POI's that is plotted. So as it goes through the list of Lats's and long's, the name is different. With the code as it is, the title being applied is the last line of the CSV. – Avi909gp Aug 28 '17 at 08:10
  • In the while loop you always override the siteName, that is why it is always the last value of the CSV. Add the site names in an array, just like the latlng, and call positionSite() with 2 parameters like this: positionSite(latLng position, String siteName) – Tudor Lozba Aug 28 '17 at 08:41
  • The edit of my code includes a list added for the siteName portion. This run does not add any title to the marker. I am certain that the for loop for casting the list's is where my issues is now. I guess what I am asking is how do I cast the values from both lists so that the two variables can be passed into the positionSite method correctly? – Avi909gp Aug 28 '17 at 09:40
  • Make only one for loop like this: for(int i=0; i – Tudor Lozba Aug 28 '17 at 10:02
  • Thank you! I used the single for loop and all works perfectly. Appreciate the assistance. – Avi909gp Aug 28 '17 at 11:58