简体   繁体   中英

Multiple marker in Map not showing with SupportMapFragment

I am trying to add multiple markers in GoogleMaps. I am using Google SupportMapFragment. Onload my Map should show multiple markers based on data in arraylist however it shows only one marker. I have researched on this and i saw this question on SO but i do not why there is only one marker showing on map.

Update i debugged my code and realized that in this line

mMap.addMarker(new MarkerOptions().position(position));

only one position is getting passed before this line all data was being passed

Here is my code for same

 @Override
    public void onMapReady(GoogleMap googleMap) {
        this.mMap = googleMap;
        // Add a marker in Sydney, Australia,
        // and move the map's camera to the same location.
       // LatLng sydney = new LatLng(19.2372, 72.8441);
        for(int i=0;i<providers.size();i++){
            NearbyDataProvider provider = providers.get(i);
            LatLng position = new LatLng(Double.parseDouble(provider.getLattitude())
                    ,Double.parseDouble(provider.getLongitude()));
            mMap.addMarker(new MarkerOptions().position(position));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(position));
        }

    }

NearByDataProvider.class

public class NearbyDataProvider { int image; String place; String lattitude; String longitude;

 public NearbyDataProvider(int image, String place, String lattitude, String longitude) { this.setImage(image); this.setPlace(place); this.setLattitude(lattitude); this.setLongitude(longitude); } public int getImage() { return image; } public void setImage(int image) { this.image = image; } public String getPlace() { return place; } public void setPlace(String place) { this.place = place; } public String getLattitude() { return lattitude; } public void setLattitude(String lattitude) { this.lattitude = lattitude; } public String getLongitude() { return longitude; } public void setLongitude(String longitude) { this.longitude = longitude; } } 

LatLong to be passed

private String[] latitude = {"19.2372","19.1998","19.1802","19.1551","19.1405"};
    private String[] longitude = {"72.8441","72.8426","72.8554","72.8679","72.8422"};

check this,

ArrayList<MarkerData> markersArray = new ArrayList<MarkerData>();

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

createMarker(markersArray.get(i).getLatitude(), markersArray.get(i).getLongitude(), markersArray.get(i).getTitle(), 
markersArray.get(i).getSnippet(), markersArray.get(i).getIconResID());
}


private void createMarker(double latitude, double longitude, String title, String snippet, int iconResID) {

 googleMap.addMarker(new MarkerOptions()
        .position(new LatLng(latitude, longitude))
        .anchor(0.5f, 0.5f)
        .title(title)
        .snippet(snippet));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM