How to set MapView zoom level in onCreate ()?

I am developing a OneMap application for Android, and the code is as follows:

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

I am lost in calculating how to set the zoom level when I first load the map on the emulator, as when loading, the map is too small.

Can anyone help me with this?

Any help would be greatly appreciated.

+4
source share
3 answers
 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
source

Firstly, you need to know your current location, now you can use the new location api, here is the guide . then you can add the command below under Onconnect()

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

but remember .connect () LocationClient in onCreate ().

Here the error message you get if you do not follow Android: on com.google.android.gms.internal.uy (Unknown Source)

0
source

It looks like you are using ArcGIS maps. Please use the code example below to set the zoom level when starting maps.

 <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" /> 

You can also set the activity file,

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

Let me know if this works for you.

0
source

Source: https://habr.com/ru/post/1388433/


All Articles