0

Hi I am developing small android application in which I want to display map and some markers on map. I have list of latlang values and i want to display it on map. I tried this in following way :

for(int pin=0; pin<pins.size(); pin++)
            {
                LatLng pinLocation = new LatLng(Float.parseFloat(pins.get(pin).latitude), Float.parseFloat(pins.get(pin).longitude));
                Marker storeMarker = map.addMarker(new MarkerOptions()
                .position(pinLocation)
                .title(pins.get(pin).pinname)
                .snippet(pins.get(pin).address)
                );
            }

So my problem is that when I try above method it just display last marker not showing all marker. How to do this. Need help. thank you.

nilkash
  • 7,408
  • 32
  • 99
  • 176
  • Refer this one maybe useful ...http://wptrafficanalyzer.in/blog/adding-multiple-marker-locations-in-google-maps-android-api-v2-and-save-it-in-shared-preferences/ – Aravin Sep 16 '13 at 11:46
  • 1
    Please follow the link http://stackoverflow.com/questions/13855049/how-to-show-multiple-markers-on-mapfragment-in-google-map-api-v2 – Amit Sep 16 '13 at 11:53

4 Answers4

2
for(int pin=0; pin<pins.size(); pin++)
{
        LatLng pinLocation = new LatLng(Float.parseFloat(pins.get(pin).latitude), Float.parseFloat(pins.get(pin).longitude));
        Marker storeMarker = map.addMarker(new MarkerOptions()
        .position(pinLocation )-->here i had made some changes add "pinLocation" instead of "storeLocation"
        .title(pins.get(pin).pinname)
        .snippet(pins.get(pin).address)
        );
}

and after first check size of pins.size() ..

General Grievance
  • 4,555
  • 31
  • 31
  • 45
QuokMoon
  • 4,387
  • 4
  • 26
  • 50
1

You can use like this:

for (int i = 0; i < pins.size(); i++) {

 double lati=Double.parseDouble(pins.get(i).latitude);
 double longLat=Double.parseDouble(pins.get(i).longitude);
 MAP.addMarker(new MarkerOptions().
 position(
 new LatLng(lati,longLat)).title(pins.get(i).pinname).snippet(pins.get(i).address));


 }
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

Use shared preferences like below

  // Opening the sharedPreferences object
        sharedPreferences = getSharedPreferences("location", 0);

        // Getting number of locations already stored
        locationCount = sharedPreferences.getInt("locationCount", 0);

        // Getting stored zoom level if exists else return 0
        String zoom = sharedPreferences.getString("zoom", "0");

        // If locations are already saved
        if(locationCount!=0){

            String lat = "";
            String lng = "";

            // Iterating through all the locations stored
            for(int i=0;i<locationCount;i++){

                // Getting the latitude of the i-th location
                lat = sharedPreferences.getString("lat"+i,"0");

                // Getting the longitude of the i-th location
                lng = sharedPreferences.getString("lng"+i,"0");

                // Drawing marker on the map
                drawMarker(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
            }

For marking Marker:

             SharedPreferences.Editor editor = sharedPreferences.edit();

            // Storing the latitude for the i-th location
            editor.putString("lat"+ Integer.toString((locationCount-1)), Double.toString(point.latitude));

            // Storing the longitude for the i-th location
            editor.putString("lng"+ Integer.toString((locationCount-1)), Double.toString(point.longitude));

            // Storing the count of locations or marker count
            editor.putInt("locationCount", locationCount);

            /** Storing the zoom level to the shared preferences */
            editor.putString("zoom", Float.toString(googleMap.getCameraPosition().zoom));

            /** Saving the values stored in the shared preferences */
            editor.commit();

            Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();

Refer this one...source code is availbale

Aravin
  • 4,126
  • 1
  • 23
  • 39
0
for (int i = 0; i < ComponentMapList.size(); i++) {
                    String city = ComponentMapList.get(i).getCity();
                    if (city != null) {
                        center = CameraUpdateFactory.newLatLng(new LatLng(
                                ComponentMapList.get(i).getLat(),
                                ComponentMapList.get(i).getLng()));
                        mMap.addMarker(new MarkerOptions().position(
                                new LatLng(ComponentMapList.get(i).getLat(),
                                        ComponentMapList.get(i).getLng()))
                                .title(city));
                    }
                }
dipali
  • 10,966
  • 5
  • 25
  • 51