In the previous chapter, the map is displayed simply, and the location, proportion, and angle of the map to be displayed are not initialized. This chapter describes how to specify a series of map parameters.
Specify parameters in XML format, where class = "com. google. android. GMS. maps. supportmapfragment ", Google Maps Android API requires the API level to be at least 12 to support class =" com. google. android. GMS. maps. mapfragment ". if the version is earlier than 12, the supportmapfragment class can be called. The class property is the same as the Android: Name property.
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment" map:cameraBearing="112.5" map:cameraTargetLat="-33.796923" map:cameraTargetLng="150.922433" map:cameraTilt="30" map:cameraZoom="13" map:mapType="normal" map:uiCompass="false" map:uiRotateGestures="true" map:uiScrollGestures="false" map:uiTiltGestures="true" map:uiZoomControls="false" map:uiZoomGestures="true"/>
Generally, you need to call a map by specifying the specific attribute of GoogleMap through code. if you add a mapfragment, (or mapview class) programming, you can configure its initial state by specifying the googlemapoptions object. For more information about googlemapotions, see.
GoogleMapOptions options = new GoogleMapOptions();options.mapType(GoogleMap.MAP_TYPE_SATELLITE).compassEnabled(false).rotateGesturesEnabled(false).tiltGesturesEnabled(false);
If mapfragment is used, you can use mapfragment. newinstance (googlemapoptions options) to specify attributes. If mapview is used, you can use new mapview (context, googlemapoptions) to specify attributes. Of course, some of these attributes can also be set through uisetaskus = MMAP. getuisetask.
Package COM. example. googleMap; import COM. google. android. GMS. maps. googleMap; import COM. google. android. GMS. maps. googlemapoptions; import COM. google. android. GMS. maps. mapview; import COM. google. android. GMS. maps. uisettings; import COM. google. android. GMS. maps. model. cameraposition; import COM. google. android. GMS. maps. model. latlng; import COM. google. android. GMS. maps. model. markeroptions; import android. app. activity; import android. OS. bundle; import android. view. viewgroup. layoutparams; public class mainactivity extends activity {private GoogleMap MMAP; private mapview mmapview; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); googlemapoptions Options = new googlemapoptions (); options. maptype (GoogleMap. map_type_normal); options. camera (New cameraposition (New latlng (22.545033, 113.924752), 14, 0, (float) 112.5); mmapview = new mapview (this, options); mmapview. setlayoutparams (New layoutparams (layoutparams. match_parent, layoutparams. match_parent); mmapview. oncreate (savedinstancestate); setcontentview (mmapview); MMAP = mmapview. getmap (); MMAP. addmarker (New markeroptions (). position (New latlng (22.545033, 113.924752 )). title ("near Yuquan Road, Nanshan District, Shenzhen"); uisetpolicus = MMAP. getuisettings (); US. setzoomcontrolsenabled (false); US. setzoomgesturesenabled (true); US. setscrollgesturesenabled (true); US. setcompassenabled (false); US. setrotategesturesenabled (true); US. settiltgesturesenabled (true) ;}@ overrideprotected void onresume () {super. onresume (); mmapview. onresume () ;}@ overrideprotected void onpause () {super. onpause (); mmapview. onpause () ;}@ overrideprotected void ondestroy () {super. ondestroy (); mmapview. ondestroy ();}}