Google Maps Android V2 development BASICS (2)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.