2014-10-18 29 views
0
public class MapActivity extends SherlockFragmentActivity{ 
// Google Map 
private GoogleMap googleMap; 
String longitude="0"; 
String latitude="0"; 
String title=""; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    try 
    { 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.activity_map); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     getSupportActionBar().setHomeButtonEnabled(true); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 
     try { 
      // Loading map 
      initilizeMap(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     }} 
     catch(Exception eos) 
     { 

     } 


} 

/** 
* function to load map. If map is not created it will create it for you 
* */ 
private void initilizeMap() { 
    try 
    { 
      if (googleMap == null) { 
     String longitude="27.175015"; 
     String latitude="78.042155"; 
     double savedLat = Double.parseDouble(longitude); 
     double savedLng =Double.parseDouble(latitude); 
     LatLng cameraLatLng = new LatLng(savedLat, savedLng); 
     googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
       R.id.map)).getMap(); 
     googleMap.addMarker(new MarkerOptions() 
     .position(new LatLng(Float.parseFloat(latitude), Float.parseFloat(longitude))).title("Marker") 
     .title("mazen")); 
     googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, 17)); 
     // check if map is created successfully or not 
     if (googleMap == null) { 

     } 
      } 
    } 
    catch(Exception e) 
    { 

    } 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    initilizeMap(); 
} 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (item.getItemId() == android.R.id.home) { 
     finish(); 
     overridePendingTransition(R.anim.dux_sld_lft_in, 
       R.anim.dux_sld_lft_out); 
     return true; 
    }else { 
     return super.onOptionsItemSelected(item); 
    } 
} 
@Override 
public void onBackPressed() { 
    // TODO Auto-generated method stub 
    super.onBackPressed(); 
    overridePendingTransition(R.anim.dux_sld_lft_in, R.anim.dux_sld_lft_out); 
} 
public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); 
    return true; 
} 

}添加Makrer不能正常工作的android

上午在這裏添加標記,但沒有標記說明爲什麼?我怎樣才能添加多個標記到多個地方?很可笑的錯誤......因爲我真的exacty的教程中,我讀.. 希望有人能養活我完成這項任務所需nessary幫助

回答

0

使用addMarker()

,如:

myMap.addMarker(new MarkerOptions().position(yourLatLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.yourmarkericon))); 

其中MYMAPGoogleMapyourLatlng的對象是Latlng凡要添加標記和yourmarkericon是要在地圖上顯示

參考

https://developers.google.com/maps/documentation/android/marker

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Marker

簡易教程

http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

+0

圖標沒有什麼區別我t不起作用。 – user3278732 2014-10-18 22:09:03

+0

顯示錯誤日誌。 – 2014-10-18 22:21:14

+0

它適用於不同的地方,但不適用於印度。非常有趣 – user3278732 2014-10-18 22:21:34