2012-06-12 68 views
1

我在使用osmdroid映射API的android映射應用程序中工作,直到現在我能夠顯示地圖(使用MapView類),但我想知道如何顯示我的位置地圖,之後我讀到它,我知道有一類叫做MyLocationOverlay我試圖使用它,但應用程序返回空白page.here是我的代碼:osmdroid中的MyLocationOverlay

public class AbodyActivity extends Activity 
{ 
private MapView mapView; 
private MapController mapController; 
private MyLocationOverlay myLocationoverlay; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    initializemap(); 
    myLocationoverlay = new MyLocationOverlay(this, mapView); 
    myLocationoverlay.disableMyLocation(); // not on by default 
    myLocationoverlay.disableCompass(); 
    myLocationoverlay.disableFollowLocation(); 
    myLocationoverlay.setDrawAccuracyEnabled(true); 
    myLocationoverlay.runOnFirstFix(new Runnable() { 
    public void run() { 
      mapController.animateTo(myLocationoverlay 
        .getMyLocation()); 
     } 
    }); 
    mapView.getOverlays().add(myLocationoverlay); 
} 
public void initializemap() 
{ 
mapView = (MapView) this.findViewById(R.id.mapView); 
mapView.setTileSource(TileSourceFactory.MAPNIK); 
mapView.setBuiltInZoomControls(true); 
mapView.setMultiTouchControls(true); 
mapController = this.mapView.getController();  
mapController.setZoom(6); 
} 

} 

而且這裏是它的權限我用過:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

回答

4

您確定要:

myLocationoverlay.disableMyLocation(); 

不禁用位置查找程序方法,因此您的Runnable永遠不會被調用?

+0

感謝馬丁·皮爾曼你的有趣。我是不明白你的問題,但馬雲的應用程序現在正在賴特後,我這兩行添加到它: [myLocationoverlay.enableMyLocation();] [調用MapView.getOverlays ()。新增(myLocationoverlay);] – harhouf