C#开发Android百度地图手机应用程序(多地图展示)

 更新时间:2016年02月04日 09:54:03   作者:rainmj  
这篇文章主要介绍了C#开发Android百度地图手机应用程序(多地图展示)的相关资料,需要的朋友可以参考下

一、简介

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

文件名:Demo04MultiMapView.cs

简介:介绍多MapView的使用

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

二、示例

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.baidu.mapapi.map.TextureMapFragment" />
<fragment
android:id="@+id/map2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.baidu.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.baidu.mapapi.map.TextureMapFragment" />
<fragment
android:id="@+id/map4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.baidu.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百度地图手机应用程序(多地图展示)的相关内容,希望对大家有所帮助。

相关文章

  • C# 向二进制文件进行读写的操作方法

    C# 向二进制文件进行读写的操作方法

    该例子使用 BinaryStream 和 BinaryWriter 对二进制文件进行读写操作先上代码再根据我理解的所分享给各位朋友
    2013-04-04
  • Unity游戏开发实现背包系统的示例详解

    Unity游戏开发实现背包系统的示例详解

    这篇文章主要为大家介绍了Unity游戏开发实现背包系统的示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • C#实现应用程序的监控与调试的示例代码

    C#实现应用程序的监控与调试的示例代码

    日志记录是软件开发中不可或缺的功能,它能帮助开发者在应用程序运行时记录重要信息,本文就来介绍一下常用日志记录功能以及常用的日志库,感兴趣的可以了解一下
    2024-03-03
  • C#实现Xml序列化与反序列化的方法

    C#实现Xml序列化与反序列化的方法

    这篇文章主要介绍了C#实现Xml序列化与反序列化的方法,将序列化与反序列化的方法封装入一个类文件中,包含了较为详尽的注释说明,非常具有实用价值,需要的朋友可以参考下
    2014-12-12
  • Visual Stodio2022中没有mysql.dll的解决办法

    Visual Stodio2022中没有mysql.dll的解决办法

    这篇文章介绍了Visual Stodio2022中没有mysql.dll的解决办法,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-12-12
  • c#格式化数字的方法

    c#格式化数字的方法

    这篇文章主要介绍了c#格式化数字的方法,涉及C#针对数字转化的相关技巧,需要的朋友可以参考下
    2015-05-05
  • c#中如何获取指定字符前的字符串

    c#中如何获取指定字符前的字符串

    这篇文章主要介绍了c#中如何获取指定字符前的字符串问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-03-03
  • C#解析json字符串总是多出双引号的原因分析及解决办法

    C#解析json字符串总是多出双引号的原因分析及解决办法

    json好久没用了,今天在用到json的时候,发现对字符串做解析的时候总是多出双引号,下面给大家介绍C#解析json字符串总是多出双引号的原因分析及解决办法,需要的朋友参考下吧
    2016-03-03
  • C#实现文本读取的7种方式

    C#实现文本读取的7种方式

    这篇文章主要介绍了C#实现文本读取的7种方式,文本读取在上位机开发中经常会使用到,实现的方式也有很多种,下面我们就来分享七种方式,需要的小伙伴可以参考一下
    2022-05-05
  • c#执行外部命令示例分享

    c#执行外部命令示例分享

    c#执行外部命令示例分享,大家参考使用吧
    2013-12-12

最新评论