2012-09-27 17 views
0

我有一張地圖,我想在上面放一個標記,但標記不顯示。這裏是我的代碼:指針不顯示在我的地圖上

import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import com.google.android.maps.MyLocationOverlay; 
import com.google.android.maps.OverlayItem; 

public class MapDetailActivity extends MapActivity 
{ 
    private final static String TAG = MapDetailActivity.class.getSimpleName(); 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.map_view); 


     // get longitude and latitude values from detail activity/object 
     Bundle bundle = this.getIntent().getExtras(); 
     float latitude = bundle.getFloat("uie.top25.seattle.latitude"); 
     float longitude = bundle.getFloat("uie.top25.seattle.longitude"); 

     Log.i(TAG, "Latitude that is set : " + latitude); 
     Log.i(TAG, "Longitude that is set : " + longitude); 
     // create longitude and latitude map points 
     Double lat = latitude * 1E6; 
     Double lon = longitude * 1E6; 

     // create point on map 
     GeoPoint point = new GeoPoint(lat.intValue(), lon.intValue()); 
     OverlayItem oi = new OverlayItem(point, null, null); 
     MapView mapView = (MapView) this.findViewById(R.id.myMapView); 
     MapController mapController = mapView.getController(); 
     // set point on map 
     mapController.animateTo(point); 
     oi.setMarker(oi.getMarker(R.drawable.mm_20_red)); 
     // set zoom level 
     mapController.setZoom(19); 

    } 

    @Override 
    protected boolean isRouteDisplayed() 
    { 
     // No driving directions, so this method returns false 
     return false; 
    } 

} 

有人能告訴我我做錯了什麼嗎?

回答

0

你需要去通過文檔和示例,但基本步驟是:

1-通過從google maps中擴展itemizedOverlay來創建您的itemizedOverlay。

2將疊加項目添加到您的項目化疊加層,並設置標記或使用上一步中定義的缺省值。

逐項疊加3加入的MapView覆蓋有:

mapview.getoverlays().add(myItemizedOverlay); 

剛過你有覆蓋增加的MapView覆蓋列表,覆蓋將MapView類被認爲是要求在屏幕上繪製(調用onDraw方法)

祝你好運。