The 3rd chapter in C # to write Baidu map Android mobile app (4th speaking)

Source: Internet
Author: User

Category: C #, Android; Date: 2016-02-04

3.4 Example 4--layer presentation one, introduction

1. Map type

Baidu Maps Android SDK 3.7.1 provides two types of map resources (normal vector and satellite), and developers can use the Maptype attribute (C #) in Baidumap to set the map type. The C # core code is as follows:

Mmapview = findviewbyid<texturemapview>= mmapview.map; // Set basemap display mode: normal map mbaidumap.maptype = baidumap.maptypenormal; // Set BASEMAP display mode: satellite map mbaidumap.maptype = baidumap.maptypesatellite;

2. Real-time traffic map

At present, the nationwide support of multiple cities in real-time road traffic inquiries, and will be opened in other cities.

Which cities currently have real-time traffic maps?

Currently (2016-01-27) 31 cities have been opened, respectively, Nanjing, Guangzhou, Chongqing, Dongguan, Changchun, Taizhou, Fuzhou, Jinhua, Beijing, Changzhou, Hangzhou, Wenzhou, Dalian, Nanchang, Ningbo, Shenyang, Zhongshan, Zhuhai, Foshan, Quanzhou, Shijiazhuang, Chengdu, Qingdao, Shenzhen, Wuhan, Urumqi, Changsha , Shanghai, Tianjin, Wuxi, Xiamen. Other cities will be open in succession.

The C # core code for opening real-time traffic on a map is as follows:

Mmapview = findviewbyid<texturemapview>= mmapview.map; // Open Traffic Map true;

3, Baidu City Heat Force diagram

Baidu Map SDK for the vast number of developers to open the heat of the local mapping ability, and then further open the Baidu's own data of the city heat map layer, to help developers to build more diverse forms of mobile applications.

The nature and use of Baidu's urban heat map similar to the real-time traffic map, just need to simple interface call, you can display the rich style of Baidu city maps.

On the map to open the Baidu City heat force diagram of the C # core code as follows:

Mmapview = findviewbyid<texturemapview>= mmapview.map; // Open Traffic Map true;

On the basis of the previous example, you only need to add the following steps.

2. Add Demo04_layers.axml File

<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_width="fill_parent"Android:layout_height="fill_parent"android:orientation="Vertical"> <LinearLayout android:layout_width="fill_parent"Android:layout_height="wrap_content"android:orientation="Horizontal"> <Radiogroup Android:id="@+id/radiogroup"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_weight="2"android:orientation="Horizontal"> <RadioButton Android:id="@+id/normal"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_weight="1"android:checked="true"Android:text="General Diagram"/> <RadioButton Android:id="@+id/statellite"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_weight="1"Android:text="Satellite map"/> </RadioGroup> <CheckBox Android:id="@+id/traffice"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_weight="1"android:checked="false"Android:text="Traffic Map"/> <CheckBox Android:id="@+id/baiduheatmap"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_weight="1"android:checked="false"Android:text="Baidu City Thermal Map"/> </LinearLayout> <Com.baidu.mapapi.map.TextureMapView Android:id="@+id/bmapview"Android:layout_width="fill_parent"Android:layout_height="fill_parent"android:clickable="true"/></linearlayout>

2. Add Demo04Layers.cs File

Add the file under the Srcsdkdemos folder.

usingAndroid.app;usingAndroid.Content.PM;usingAndroid.os;usingAndroid.widget;usingCom.Baidu.Mapapi.Map;namespacebdmapv371demos.srcsdkdemos{/// <summary>    ///Show control method for map layer display/// </summary>[Activity (Label ="@string/demo_name_layers", Configurationchanges= Configchanges.orientation |Configchanges.keyboardhidden, Screenorientation=screenorientation.sensor)] Public classdemo04layers:activity {//Texturemapview is the map master control        PrivateTexturemapview Mmapview; PrivateBaidumap Mbaidumap; protected Override voidOnCreate (Bundle savedinstancestate) {Base.            OnCreate (savedinstancestate);            Setcontentview (Resource.Layout.demo04_layers); Mmapview= findviewbyid<texturemapview>(Resource.Id.bmapView); Mbaidumap=Mmapview.map;            Mbaidumap.setmapstatus (MAPSTATUSUPDATEFACTORY.NEWLATLNG (mainactivity.henanuniversity)); //Set basemap display mode: normal diagram            varnormal = Findviewbyid<radiobutton>(Resource.Id.normal); Normal. Click+=Delegate{Mbaidumap.maptype=Baidumap.maptypenormal;            }; //Setting the BASEMAP display mode: satellite map            varStatellite = findviewbyid<radiobutton>(Resource.Id.statellite); Statellite. Click+=Delegate{Mbaidumap.maptype=Baidumap.maptypesatellite;            }; //whether to show traffic map            varTraffice = findviewbyid<checkbox>(Resource.Id.traffice); Traffice. Checkedchange+ = (s, e) = ={mbaidumap.trafficenabled=e.ischecked;            }; //whether to show the thermal map            varBaiduheatmap = findviewbyid<checkbox>(RESOURCE.ID.BAIDUHEATMAP); Traffice. Checkedchange+ = (s, e) = ={mbaidumap.baiduheatmapenabled=e.ischecked;        }; }        protected Override voidOnPause () {mmapview.onpause (); Base.        OnPause (); }        protected Override voidOnresume () {mmapview.onresume (); Base.        Onresume (); }        protected Override voidOnDestroy () {Mmapview.ondestroy (); Base.        OnDestroy (); }    }}

4. Modify the MainActivity.cs file

Add the following code in the Demos field definition of the MainActivity.cs file.

          // Example 4--layer display            New Demoinfo<activity>(Resource.String.demo_title_layers,                Resource.String.demo_desc_layers,                 New demo04layers ()),

Run.

The 3rd chapter in C # to write Baidu map Android mobile app (4th speaking)

Related Article

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.