google maps marker array?

。_饼干妹妹 提交于 2020-01-14 05:25:09

问题


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



来源:https://stackoverflow.com/questions/28503562/google-maps-marker-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!