how to show multiple marker on google map android

Aoyama Nanami

i want to show location with multiple markers on google maps android, the problem is when i run my apps, it just show one location/marker, this is my code :

public class koordinatTask extends AsyncTask<String, String, String>
    {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            setProgressBarIndeterminateVisibility(true);
        }

        protected String doInBackground(String... args) {
             String url = "http://absc?action=p04&prov="+link_kode+"&tipe=";
             JSONArray data = null;
            try {
                JSONParser jParser = new JSONParser();
                JSONObject json = jParser.getJSONFromUrl(url);
                // Getting Array of data
                data = json.getJSONArray(real_data);
                System.out.println("realisasi done");

                for(int i = 0; i < data.length(); i++){
                    JSONObject c = data.getJSONObject(i);
                    HashMap<String, String> map = new HashMap<String, String>();
                    HashMap<String, Double> map1 = new HashMap<String, Double>();
                    x_lat = c.getDouble(x_cord);
                    y_long = c.getDouble(y_cord);
                    label = c.getString(prov_label);
                    map1.put(x_cord, x_lat);
                    map1.put(y_cord, y_long);
                    map.put(prov_label, label);
                    ProvinsiList.add(map);
                    ProvinsiList.add(map1);
                    System.out.println(x_lat);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String file_url) {
            LatLng MAP_PUPI = new LatLng(x_lat, y_long);
            Marker Pupi = map.addMarker(new MarkerOptions().position(
                    new LatLng(x_lat, y_long)).title(label));
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(MAP_PUPI, 15));

            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
        }   
    }

i don't know where's my fault, i hope somebody can help me to solve my problem, thank u verymuch

Piyush

Use this:

for (int i = 0; i < yourArrayList.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));
 }

Or you can also use this:

 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)
                );
            }

where latitude and longitude is the String to which you have store in your arraylist with different name.....

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Google map with marker does not show in android browser

How to show a FancyBox video on a Google Map marker?

How to show google map and marker on the same layout?

Show marker to Google Map on Click

Android Google map show custom marker and clustering issue

Show and update icon of marker in java android google map

Xamarin Android - Google Map Marker always show the same info

how to show an info window without showing the icon of a marker in google map

How to make google map multiple marker's infowindow stays opened android

Android google map custom marker

Android Google Map Marker With Label?

How to tap on ios google map marker programatically or show info window of marker?

How can move camera in google map to marker android

How to manage click on marker which is not in Cluster in Android Google Map API?

How to set tag to Google Map's marker in Android?

How to initialize a google map so that marker placed is visible in android

How can animated marker google map like shown in image in android?

how to count number of click on google map marker in android

how to add images getting from server to google map android as a marker?

Android Google Map how to check if user is in marker rectangle region

How to add a Google Map Marker

How to position Google Map Marker?

How to add Marker in Google map

How to remove specific multiple marker from google map instead of single or all marker

Always show map marker title in Android

Show multiple marker on google map (API V2 ) from database

showing multiple characters in google map marker

Can not add multiple marker in google map

google map multiple marker issue in php