2011-12-29 90 views
4

我正在開發一個OneMap的Android應用程序和代碼如下:如何在onCreate()中設置MapView縮放級別?

private MapView map; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     map = (MapView) findViewById(R.id.map); 

     map.addLayer(new ArcGISTiledMapServiceLayer(Practice_3.this, 
       "http://www.onemap.sg/ArcGIS/rest/services/BASEMAP/MapServer"));} 

我在搞清楚如何設置縮放級別時丟失地圖首次加載在模擬器上加載時,地圖太小。

任何人都可以幫助我嗎?

任何幫助將不勝感激。

+0

許多教程可以在線獲取Google地圖應用程序的Android版。這似乎是你沒有檢查他們。不要爲基本的東西使用stackoverflow,它不好。 – 2011-12-29 10:19:42

+0

@Yugandhar Babu你是對的,但這裏的這些詞看起來不友好 – atom2ueki 2013-10-14 15:40:22

回答

0
public class MyMap_MapControllerActivity extends MapActivity { 

    private MapView mapView; 
    //private MapController mapController; 
    MapView.LayoutParams lp; 
    int y = 10; 
     int x = 10; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mapView = (MapView)findViewById(R.id.map_view); 
     mapView.setSatellite(true); 
     mapView.setStreetView(true); 
     mapView.setTraffic(true); 



    GeoPoint center = mapView.getMapCenter(); 
    int latSpan = mapView.getLatitudeSpan(); 
    int longSpan = mapView.getLongitudeSpan(); 




    lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, 
    MapView.LayoutParams.WRAP_CONTENT, 
    x, y, 
    MapView.LayoutParams.TOP_LEFT); 
    View zoomControls = mapView.getZoomControls(); 
    mapView.addView(zoomControls, lp); 
    mapView.displayZoomControls(true); 
    } 



    @Override 
    protected boolean isRouteDisplayed() { 
     // TODO Auto-generated method stub 
     return false; 
    } 
    } 
+0

嗨,非常感謝您的回覆。 – user1097856 2011-12-30 01:03:40

0

首先你需要知道你的當前位置,現在你可以使用新的位置API,這裏是guide。 那麼你可以下的onCreate下Onconnect()

LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());   
map.moveCamera(CameraUpdateFactory.newLatLng(latlng)); 
map.animateCamera(CameraUpdateFactory.zoomTo(2.0f)); 

添加下面的命令,但記得.connect()LocationClient()。

這裏是錯誤消息,如果你不遵循 Android: at com.google.android.gms.internal.u.y(Unknown Source)

0

它看起來像使用ArcGIS地圖`重新你會得到。 請使用下面的示例代碼來設置地圖啓動時的縮放級別。

<com.esri.android.map.MapView 
    android:id="@+id/map" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    mapoptions.MapType="Topo" 
    mapoptions.ZoomLevel="13" 
    mapoptions.center="33.666354, -117.903557" /> 

您還可以設置在活動文件,

MapOptions options = new MapOptions(MapType.TOPO, 23, -110, 9); 

讓我知道它是否適合你。