android地图 demo,Android地图控件之多地图展示

一、简介

地图控件自v2.3.5版本起,支持多实例,即开发者可以在一个页面中建立多个地图对象,并且针对这些对象分别操作且不会产生相互干扰。

文件名:Demo04MultiMapView.cs

简介:介绍多MapView的使用

详述:在一个界面内,同时建立四个TextureMapView控件;

二、示例

1、运行截图在x86模拟器中的运行效果如下:

3c1cc4fa10989507871f3a29487d1db3.png

在上一节例子的基础上,只需要再增加下面的步骤即可。

2、添加demo05_multimap.axml文件在layout文件夹下添加该文件,将其改为下面的代码:

xmlns:map="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginBottom="5dp"

android:layout_weight="1"

android:orientation="horizontal" >

android:id="@+id/map1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginRight="5dp"

android:layout_weight="1"

class="com.baidu.mapapi.map.TextureMapFragment" />

android:id="@+id/map2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

class="com.baidu.mapapi.map.TextureMapFragment" />

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

android:orientation="horizontal" >

android:id="@+id/map3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginRight="5dp"

android:layout_weight="1"

class="com.baidu.mapapi.map.TextureMapFragment" />

android:id="@+id/map4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="1"

class="com.baidu.mapapi.map.TextureMapFragment" />

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

{

///

/// 在一个Activity中展示多个地图

///

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

}

///

/// 初始化Map

///

private void InitMap()

{

MapStatusUpdate u1 = MapStatusUpdateFactory.NewLatLng(Geo_BeiJing);

TextureMapFragment map1 = FragmentManager.FindFragmentById(Resource.Id.map1);

map1.BaiduMap.SetMapStatus(u1);

MapStatusUpdate u2 = MapStatusUpdateFactory.NewLatLng(Geo_ShangHai);

TextureMapFragment map2 = FragmentManager.FindFragmentById(Resource.Id.map2);

map2.BaiduMap.SetMapStatus(u2);

MapStatusUpdate u3 = MapStatusUpdateFactory.NewLatLng(Geo_GuangZhou);

TextureMapFragment map3 = FragmentManager.FindFragmentById(Resource.Id.map3);

map3.BaiduMap.SetMapStatus(u3);

MapStatusUpdate u4 = MapStatusUpdateFactory.NewLatLng(Geo_ShenZhen);

TextureMapFragment map4 = FragmentManager.FindFragmentById(Resource.Id.map4);

map4.BaiduMap.SetMapStatus(u4);

}

}

}

4、修改MainActivity.cs文件

在MainActivity.cs文件的demos字段定义中添加下面的代码。

//示例5--多地图展示

new DemoInfo(Resource.String.demo_title_multimap,

Resource.String.demo_desc_multimap,

new Demo05MutiMapView()),

运行观察结果。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值