2013-06-19 47 views
2

我正在使用谷歌地圖v2 api。因爲我需要顯示多個標記和多個疊加層。我對此沒有任何想法。如果有人知道答案,請分享你的想法。謝謝。如何在v2 google map中添加多個標記和疊加層?

對於單標記和覆蓋我使用此代碼

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

回答

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


     } 
    } 
相關問題