C#開辟Android百度地圖手機運用法式(多地圖展現)。本站提示廣大學習愛好者:(C#開辟Android百度地圖手機運用法式(多地圖展現))文章只能為提供參考,不一定能成為您想要的結果。以下是C#開辟Android百度地圖手機運用法式(多地圖展現)正文
1、簡介
地圖控件自v2.3.5版本起,支撐多實例,即開辟者可以在一個頁面中樹立多個地圖對象,而且針對這些對象分離操作且不會發生互相攪擾。
文件名:Demo04MultiMapView.cs
簡介:引見多MapView的應用
胪陳:在一個界面內,同時樹立四個TextureMapView控件;
2、示例
1、運轉截圖
在x86模仿器中的運轉後果以下:

在上一節例子的基本上,只須要再增長上面的步調便可。
2、添加demo05_multimap.axml文件
在layout文件夾下添加該文件,將其改成上面的代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="5dp" android:layout_weight="1" android:orientation="horizontal" > <fragment android:id="@+id/map1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_weight="1" class="com.百度.mapapi.map.TextureMapFragment" /> <fragment android:id="@+id/map2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" class="com.百度.mapapi.map.TextureMapFragment" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <fragment android:id="@+id/map3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_weight="1" class="com.百度.mapapi.map.TextureMapFragment" /> <fragment android:id="@+id/map4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" class="com.百度.mapapi.map.TextureMapFragment" /> </LinearLayout> </LinearLayout>
3、添加Demo05MultiMapView.cs文件
在SdkDemos文件夾下添加該文件,然後將其內容改成上面的代碼:
using Android.App;
using Android.Content.PM;
using Android.OS;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 在一個Activity中展現多個地圖
/// </summary>
[Activity(Label = "@string/demo_name_multimap",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
ScreenOrientation = ScreenOrientation.Sensor)]
public class Demo05MutiMapView : Activity
{
private readonly LatLng Geo_BeiJing = new LatLng(39.945, 116.404);
private readonly LatLng Geo_ShangHai = new LatLng(31.227, 121.481);
private readonly LatLng Geo_GuangZhou = new LatLng(23.155, 113.264);
private readonly LatLng Geo_ShenZhen = new LatLng(22.560, 114.064);
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo05_multimap);
InitMap();
}
/// <summary>
/// 初始化Map
/// </summary>
private void InitMap()
{
MapStatusUpdate u1 = MapStatusUpdateFactory.NewLatLng(Geo_BeiJing);
TextureMapFragment map1 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map1);
map1.BaiduMap.SetMapStatus(u1);
MapStatusUpdate u2 = MapStatusUpdateFactory.NewLatLng(Geo_ShangHai);
TextureMapFragment map2 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map2);
map2.BaiduMap.SetMapStatus(u2);
MapStatusUpdate u3 = MapStatusUpdateFactory.NewLatLng(Geo_GuangZhou);
TextureMapFragment map3 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map3);
map3.BaiduMap.SetMapStatus(u3);
MapStatusUpdate u4 = MapStatusUpdateFactory.NewLatLng(Geo_ShenZhen);
TextureMapFragment map4 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map4);
map4.BaiduMap.SetMapStatus(u4);
}
}
}
4、修正MainActivity.cs文件
在MainActivity.cs文件的demos字段界說中添加上面的代碼。
//示例5--多地圖展現 new DemoInfo<Activity>(Resource.String.demo_title_multimap, Resource.String.demo_desc_multimap, new Demo05MutiMapView()),
以上所述給年夜家引見了C#開辟Android百度地圖手機運用法式(多地圖展現)的相干內容,願望對年夜家有所贊助。