如何在v2谷歌地图中添加多个标记和叠加?

时间:2013-06-19 06:09:07

标签: android google-maps google-maps-markers

我正在使用谷歌地图v2 api。在那我需要显示多个标记和多个叠加。我对此一无所知。如果有人知道答案,请分享您的想法。谢谢。

对于单个标记和叠加,我使用此代码

 hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
          .title("Hamburg")
     .snippet("Kiel is cool")
   .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

2 个答案:

答案 0 :(得分:2)

像这样使用

            LatLng one = new LatLng(2.40744, 77.014702);//Latitude and long points
        LatLng two = new LatLng(2.407440, 77.014702);
        LatLng three = new LatLng(2.4013, 76.951340000000002);
            .......
            Similarly u can use more lat and long 

         myMarkerOne = gm.addMarker(new MarkerOptions()
        .position(one)//use LatLng obj
        .title("C") 
        .snippet("dsfd")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

        myMarkerTwo = gm.addMarker(new MarkerOptions()
        .position(two)
        .title("C") 
        .snippet("dsfds")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

        myMarkerThree = gm.addMarker(new MarkerOptions()
        .position(three)
        .title("A") 
        .snippet("dfd")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));

依旧......

答案 1 :(得分:1)

Try this one.It will be better



String values[]={"2.40744, 77.014702","6.407440, 77.014702","10.4013, 76.951340000000002"};

    GoogleMap googleMap;

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


            SupportMapFragment supportMapFragment = (SupportMapFragment)
                    getSupportFragmentManager().findFragmentById(R.id.map);



            // Getting a reference to the map
            googleMap = supportMapFragment.getMap();


             for(int i=0;i<values.length;i++)
        {

            String s[] = values[i].split(",");

            String v1 = s[0];
            String v2 = s[1];
        googleMap.addMarker(new MarkerOptions()
        .position(
                new LatLng(Double.valueOf(v1),Double.valueOf(v2)))
        .title("Hi")
        .icon(BitmapDescriptorFactory
                .fromResource(R.drawable.ic_launcher)));


        }
    }