Adding multiple markers in Google Maps Api v2

爷,独闯天下 提交于 2019-11-29 22:29:07

问题


I have successfully managed to show the google map api v2. I want to add markers for my positions on it.

As per the documentation, I am only able to add one marker at a time or have to use a loop to add multiple.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo_v2);


        googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        googleMap.setMyLocationEnabled(true);

        Marker marker = googleMap.addMarker(new MarkerOptions().position(ROMA).title("Hello").snippet("Nice Place").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
}

My question is, if I have a set of 10 LatLon values and the custom images, how can i show the multiple markers in API v2.

Thanks


回答1:


Try this Link . It is best to use & It will help to how to Add Multiple markers with text on Android Google Maps API v2




回答2:


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


来源:https://stackoverflow.com/questions/15609615/adding-multiple-markers-in-google-maps-api-v2

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