Category: C#, Android, VS2015, Baidu map application; Creation date: 2016-02-04 1. Introduction File name: Demo05MapControl.cs Introduction: Introduction to panning and zooming the map, operating the map with two fingers, monitoring map click events for details Description: (1) Introduce the get and set methods of map zoom level, rotation and overlooking degree; (2) Monitor clicks and long presses
Category: C#, Android, VS2015, Baidu map application; Creation date: 2016-02-04
File name: Demo05MapControl.cs
Introduction: Introducing panning and zooming the map, operating the map with two fingers, and monitoring map click events
Details:
(1) Introducing the get and set methods of map zoom level, rotation and overlooking degree;
(2) Monitor click and long press map events;
(3) Click, double-click and long press the map to obtain the latitude and longitude coordinates of the point;
(4) Take a screenshot of the map display content. The screenshot save address is: /mnt/sdcard/test.png;
Run screenshot
The running effect in the x86 simulator is as follows:
Add this file under the layout folder and change it to the following code:
<?xml version=<span style="color: #800000;">"<span style="color: #800000;">1.0</span><span style="color: #800000;">"</span> encoding=<span style="color: #800000;">"</span><span style="color: #800000;">utf-8</span><span style="color: #800000;">"</span>?> <linearlayout xmlns:android="<span" style="color: #800000;">"<span style="color: #800000;">http://schemas.android.com/apk/res/android</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">vertical</span><span style="color: #800000;">"</span> > LinearLayout android:layout_width=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">50dip</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">horizontal</span><span style="color: #800000;">"</span> > Button android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/zoombutton</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">缩放</span><span style="color: #800000;">"</span> /> EditText android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/zoomlevel</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">10</span><span style="color: #800000;">"</span> /> Button android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/rotatebutton</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">旋转</span><span style="color: #800000;">"</span> /> EditText android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/rotateangle</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">90</span><span style="color: #800000;">"</span> /> Button android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/overlookbutton</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">俯视</span><span style="color: #800000;">"</span> /> EditText android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/overlookangle</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_weight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">1</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">-30</span><span style="color: #800000;">"</span> /> </linearlayout> TextView android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/state</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:lines</span>=<span style="color: #800000;">"</span><span style="color: #800000;">3</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">点击、长按、双击地图以获取经纬度和地图状态</span><span style="color: #800000;">"</span> /> RelativeLayout android:layout_width=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:orientation</span>=<span style="color: #800000;">"</span><span style="color: #800000;">vertical</span><span style="color: #800000;">"</span> > com.baidu.mapapi.map.TextureMapView android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/bmapView</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">fill_parent</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:clickable</span>=<span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span> /> Button android:id=<span style="color: #800000;">"</span><span style="color: #800000;">@+id/savescreen</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_width</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_height</span>=<span style="color: #800000;">"</span><span style="color: #800000;">wrap_content</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_alignParentRight</span>=<span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_alignParentTop</span>=<span style="color: #800000;">"</span><span style="color: #800000;">true</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:layout_marginTop</span>=<span style="color: #800000;">"</span><span style="color: #800000;">10dip</span><span style="color: #800000;">"</span><span style="color: #000000;"> android:text</span>=<span style="color: #800000;">"</span><span style="color: #800000;">截图</span><span style="color: #800000;">"</span> />
Add this file under the SrcSdkDemos folder, and then change its content to the following code:
<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content.PM; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Graphics; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Widget; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Map; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Model; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> System.IO; </span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos { </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span> <span style="color: #808080;">///</span><span style="color: #008000;"> 演示地图缩放,旋转,视角控制 </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span> [Activity(Label = <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_control</span><span style="color: #800000;">"</span><span style="color: #000000;">, ConfigurationChanges </span>= ConfigChanges.Orientation |<span style="color: #000000;"> ConfigChanges.KeyboardHidden, ScreenOrientation </span>=<span style="color: #000000;"> ScreenOrientation.Sensor)] </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo06MapControl : Activity, BaiduMap.IOnMapClickListener, BaiduMap.IOnMapLongClickListener, BaiduMap.IOnMapDoubleClickListener, BaiduMap.IOnMapStatusChangeListener, BaiduMap.ISnapshotReadyCallback { </span><span style="color: #0000ff;">PRivate</span><span style="color: #000000;"> TextureMapView mMapView; </span><span style="color: #0000ff;">private</span><span style="color: #000000;"> BaiduMap mBaiduMap; </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span> <span style="color: #808080;">///</span><span style="color: #008000;"> 当前地点击点 </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span> <span style="color: #0000ff;">private</span><span style="color: #000000;"> LatLng currentPt; </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> touchType; </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span> <span style="color: #808080;">///</span><span style="color: #008000;"> 用于显示地图状态的面板 </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span> <span style="color: #0000ff;">private</span><span style="color: #000000;"> TextView mStateBar; </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState) { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState); SetContentView(Resource.Layout.demo06_mapcontrol); mMapView </span>= FindViewById<texturemapview><span style="color: #000000;">(Resource.Id.bmapView); mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map; mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(MainActivity.HeNanUniversity)); mStateBar </span>= FindViewById<textview><span style="color: #000000;">(Resource.Id.state); mBaiduMap.SetOnMapClickListener(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">); mBaiduMap.SetOnMapLongClickListener(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">); mBaiduMap.SetOnMapDoubleClickListener(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">); mBaiduMap.SetOnMapStatusChangeListener(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">); </span><span style="color: #0000ff;">var</span> btnZoom = FindViewById<button><span style="color: #000000;">(Resource.Id.zoombutton); btnZoom.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { </span><span style="color: #008000;">//</span><span style="color: #008000;">处理缩放 sdk 缩放级别范围: [3.0, 19.0]</span> EditText t = FindViewById<edittext><span style="color: #000000;">(Resource.Id.zoomlevel); </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">float</span> zoomLevel = <span style="color: #0000ff;">float</span><span style="color: #000000;">.Parse(t.Text); MapStatusUpdate u </span>=<span style="color: #000000;"> MapStatusUpdateFactory.ZoomTo(zoomLevel); mBaiduMap.AnimateMapStatus(u); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> { Toast.MakeText(</span><span style="color: #0000ff;">this</span>, <span style="color: #800000;">"</span><span style="color: #800000;">请输入正确的缩放级别</span><span style="color: #800000;">"</span><span style="color: #000000;">, ToastLength.Short).Show(); } UpdateMapState(); }; </span><span style="color: #0000ff;">var</span> btnRotate = FindViewById<button><span style="color: #000000;">(Resource.Id.rotatebutton); btnRotate.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { </span><span style="color: #008000;">//</span><span style="color: #008000;">处理旋转。旋转角范围:-180~180 , 单位:度,逆时针旋转</span> EditText t = FindViewById<edittext><span style="color: #000000;">(Resource.Id.rotateangle); </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">int</span> rotateAngle = <span style="color: #0000ff;">int</span><span style="color: #000000;">.Parse(t.Text); MapStatus ms </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> MapStatus.Builder(mBaiduMap.MapStatus).Rotate(rotateAngle).Build(); MapStatusUpdate u </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewMapStatus(ms); mBaiduMap.AnimateMapStatus(u); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> { Toast.MakeText(</span><span style="color: #0000ff;">this</span>, <span style="color: #800000;">"</span><span style="color: #800000;">请输入正确的旋转角度</span><span style="color: #800000;">"</span><span style="color: #000000;">, ToastLength.Short).Show(); } UpdateMapState(); }; </span><span style="color: #0000ff;">var</span> btnOverlook = FindViewById<button><span style="color: #000000;">(Resource.Id.overlookbutton); btnOverlook.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { </span><span style="color: #008000;">//</span><span style="color: #008000;">处理俯视。俯角范围:-45~0, 单位:度</span> EditText t = FindViewById<edittext><span style="color: #000000;">(Resource.Id.overlookangle); </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">int</span> overlookAngle = <span style="color: #0000ff;">int</span><span style="color: #000000;">.Parse(t.Text); MapStatus ms </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> MapStatus.Builder(mBaiduMap.MapStatus).Overlook(overlookAngle).Build(); MapStatusUpdate u </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewMapStatus(ms); mBaiduMap.AnimateMapStatus(u); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> { Toast.MakeText(</span><span style="color: #0000ff;">this</span>, <span style="color: #800000;">"</span><span style="color: #800000;">请输入正确的俯角</span><span style="color: #800000;">"</span><span style="color: #000000;">, ToastLength.Short).Show(); } UpdateMapState(); }; </span><span style="color: #0000ff;">var</span> btnSaveScreen = FindViewById<button><span style="color: #000000;">(Resource.Id.savescreen); btnSaveScreen.Click </span>+= <span style="color: #0000ff;">delegate</span><span style="color: #000000;"> { </span><span style="color: #008000;">//</span><span style="color: #008000;"> 截图(在SnapshotReadyCallback中保存图片到sd卡)</span> mBaiduMap.Snapshot(<span style="color: #0000ff;">this</span><span style="color: #000000;">); Toast.MakeText(</span><span style="color: #0000ff;">this</span>, <span style="color: #800000;">"</span><span style="color: #800000;">正在截取屏幕图片...</span><span style="color: #800000;">"</span><span style="color: #000000;">, ToastLength.Short).Show(); UpdateMapState(); }; } </span><span style="color: #0000ff;">#region</span> 实现BaiduMap.IOnMapClickListener接口 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapClick(LatLng p0) { touchType </span>= <span style="color: #800000;">"</span><span style="color: #800000;">单击</span><span style="color: #800000;">"</span><span style="color: #000000;">; currentPt </span>=<span style="color: #000000;"> p0; UpdateMapState(); } </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> OnMapPoiClick(MapPoi p0) { </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">#endregion</span> <span style="color: #0000ff;">#region</span> 实现BaiduMap.IOnMapLongClickListener接口 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapLongClick(LatLng p0) { touchType </span>= <span style="color: #800000;">"</span><span style="color: #800000;">长按</span><span style="color: #800000;">"</span><span style="color: #000000;">; currentPt </span>=<span style="color: #000000;"> p0; UpdateMapState(); } </span><span style="color: #0000ff;">#endregion</span> <span style="color: #0000ff;">#region</span> 实现BaiduMap.IOnMapDoubleClickListener接口 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapDoubleClick(LatLng p0) { touchType </span>= <span style="color: #800000;">"</span><span style="color: #800000;">双击</span><span style="color: #800000;">"</span><span style="color: #000000;">; currentPt </span>=<span style="color: #000000;"> p0; UpdateMapState(); } </span><span style="color: #0000ff;">#endregion</span> <span style="color: #0000ff;">#region</span> 实现BaiduMap.IOnMapStatusChangeListener接口 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapStatusChange(MapStatus p0) { UpdateMapState(); } </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapStatusChangeFinish(MapStatus p0) { UpdateMapState(); } </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnMapStatusChangeStart(MapStatus p0) { UpdateMapState(); } </span><span style="color: #0000ff;">#endregion</span> <span style="color: #0000ff;">#region</span> 实现BaiduMap.ISnapshotReadyCallback接口 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnSnapshotReady(Bitmap p0) { </span><span style="color: #0000ff;">string</span> file = <span style="color: #800000;">"</span><span style="color: #800000;">/mnt/sdcard/test.png</span><span style="color: #800000;">"</span><span style="color: #000000;">; FileStream outX; </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { outX </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> FileStream(file, FileMode.Create); </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (p0.Compress( Bitmap.CompressFormat.Png, </span><span style="color: #800080;">100</span><span style="color: #000000;">, outX)) { outX.Flush(); outX.Close(); } Toast.MakeText(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">, </span><span style="color: #800000;">"</span><span style="color: #800000;">屏幕截图成功,图片保存在: </span><span style="color: #800000;">"</span> +<span style="color: #000000;"> file.ToString(), ToastLength.Short).Show(); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (FileNotFoundException e) { </span><span style="color: #0000ff;">throw</span><span style="color: #000000;"> e; } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (IOException e) { </span><span style="color: #0000ff;">throw</span><span style="color: #000000;"> e; } } </span><span style="color: #0000ff;">#endregion</span> <span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span> <span style="color: #808080;">///</span><span style="color: #008000;"> 更新地图状态显示面板 </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> UpdateMapState() { </span><span style="color: #0000ff;">if</span> (mStateBar == <span style="color: #0000ff;">null</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">return</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">string</span> state = <span style="color: #800000;">""</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (currentPt == <span style="color: #0000ff;">null</span><span style="color: #000000;">) { state </span>= <span style="color: #800000;">"</span><span style="color: #800000;">点击、长按、双击地图以获取经纬度和地图状态</span><span style="color: #800000;">"</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { state </span>= <span style="color: #0000ff;">string</span>.Format(touchType + <span style="color: #800000;">"</span><span style="color: #800000;">,当前经度:{0:f6} 当前纬度:{1:f6}</span><span style="color: #800000;">"</span><span style="color: #000000;">, currentPt.Longitude, currentPt.Latitude); } state </span>+= <span style="color: #800000;">"</span><span style="color: #800000;">\n</span><span style="color: #800000;">"</span><span style="color: #000000;">; MapStatus ms </span>=<span style="color: #000000;"> mBaiduMap.MapStatus; state </span>+= <span style="color: #0000ff;">string</span>.Format(<span style="color: #800000;">"</span><span style="color: #800000;">zoom={0:f2},rotate={1:d},overlook={2:d}</span><span style="color: #800000;">"</span><span style="color: #000000;">, ms.Zoom, (</span><span style="color: #0000ff;">int</span>)ms.Rotate, (<span style="color: #0000ff;">int</span><span style="color: #000000;">)ms.Overlook); mStateBar.Text </span>=<span style="color: #000000;"> state; } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnPause() { mMapView.OnPause(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnPause(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnResume() { mMapView.OnResume(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnResume(); } </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnDestroy() { mMapView.OnDestroy(); </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnDestroy(); } } }</span></button></edittext></button></edittext></button></edittext></button></textview></texturemapview>
Add the following code in the demos field definition of the MainActivity.cs file.
<span style="color: #008000;"> //</span><span style="color: #008000;">示例6--地图操作功能</span> <span style="color: #0000ff;">new</span> DemoInfo<activity><span style="color: #000000;">(Resource.String.demo_title_control, Resource.String.demo_desc_control, </span><span style="color: #0000ff;">new</span> Demo06MapControl()),</activity>
Run and observe the results.