【问题标题】:How to add multiple marker and overlay in v2 google map?如何在 v2 谷歌地图中添加多个标记和覆盖?
【发布时间】:2013-07-30 16:49:24
【问题描述】:

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

对于单个标记和覆盖,我使用此代码

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

【问题讨论】:

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


    【解决方案1】:

    这样使用

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

    等等..

    【讨论】:

      【解决方案2】:
      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)));
      
      
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2013-08-16
        • 1970-01-01
        • 2018-02-16
        • 2013-04-21
        • 2016-04-28
        • 1970-01-01
        • 1970-01-01
        • 2014-05-01
        • 2021-09-12
        相关资源
        最近更新 更多