google maps marker array?

2019-06-07 05:13发布

问题:

Hi guys and girls if any :))

this piece of code creates a null pointer exception

I would like to put a couple of markers in MO

LAT = Double.parseDouble(PartA); LNG = Double.parseDouble(PartB);

                        LatLng Standort = new LatLng(LAT, LNG);
                          MO[y] = mMap.addMarker(new MarkerOptions()
                                                    .position(Standort)
                                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.kreis)));
                        builder.include(MO[y].getPosition());

Array type expected - found com.google.android.gms.maps.model.maker

Definition private static Marker MOrt = null;

回答1:

I don't know my answer help you out or not.

First of all declare array , than add points and for adding marker i just start a loop with add marker function.

LatLng[] point_new = new LatLng[3];
        point_new[0] = new LatLng(24.8926596, 67.0835093);
        point_new[1] = new LatLng(48.85837,2.294481);
        point_new[2] = new LatLng(0, 0);
        for (int i = 0; i < point_new.length; i++) {
            drawMarker(point_new[i]);
        }

       //drawMarker method
        private void drawMarker(LatLng point) {
    // Creating an instance of MarkerOptions
    MarkerOptions markerOptions = new MarkerOptions();

    // Setting latitude and longitude for the marker
    markerOptions.position(point);

    // Adding marker on the Google Map
    map.addMarker(markerOptions);
}

final output

hope this will help! Happy coding