C#开发Android百度地图手机应用程序(多地图展示)
作者:rainmj 发布时间:2022-01-06 00:47:51
标签: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#实现客户端弹出消息框封装类。分享给大家供大家参考。具体如下:asp.net在服务器端运行,是不能在服务器端弹出对话框的,但
- 这篇文章主要介绍了Spring @Transactional注解失效解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的
- 最近在补看《C++ Primer Plus》第六版,这的确是本好书,其中关于智能指针的章节解析的非常清晰,一解我以前的多处困惑。C++面试过
- autoMapping和autoMappingBehavior的区别autoMappingBehaviormybatis核心配置文件中set
- 背景Timsort 是一个混合、稳定的排序算法,简单来说就是归并排序和二分插入排序算法的混合体,号称世界上最好的排序算法。Timsort一直
- 1、使用场景 因为最近项目需要国际化,需要能够支持多种国际化语言,目前需要支持三种(法
- 本文实例为大家分享了Java实现简单日历界面的具体代码,供大家参考,具体内容如下请使用JFrame、JPanel、JButton、JLabe
- 一.字符串函数1. 求字符串长度的strlensize_t strlen ( const char * str );字符串以 ‘\0'
- 1.初衷是由于调用银行接口的批量处理接口时,每次最多只能处理500条数据,但是当数据总数为510条时。我又不想第一次调用处理500条,第二次
- 本文实例为大家分享了C#实现温度转换功能的具体代码,供大家参考,具体内容如下界面图代码using System;using System.C
- 一,JDK环境变量;下载地址:HTTP://pan.baidu.com/s/1bpG3KYz1,新建变量名:JAVA_HOME,变量值:C:
- 一:背景1. 讲故事每次项目预交付的时候,总会遇到各种奇葩的坑,我觉得有必要梳理一下以及如何快速解决的,让后来人避避坑,这篇就聊聊自己的所闻
- 前言上一篇文章中我们通过自己开发了一个负载均衡组件,实现了随机算法的负载均衡功能,如果要实现其他算法,还需要修改代码增加相应的功能。这一篇文
- 示例代码如下:launch(Dispatchers.Main) { // 第一部分 fl
- C语言求三次方根前话说到C语言求根,我们一般会想到用sqrt(x)函数,它的输入值和返回值都是double型,x取整将会导致编译器错误。但是
- Volley 是一个 HTTP 库,它能够帮助 Android app 更方便地执行网络操作,最重要的是,它更快速高效。我们可以通过开源的
- 奇怪的不等于(≠)最近,栈长用 IntelliJ IDEA 看源码时发现:咦~这是什么鬼?Java 不等于的写法不是一直都是 != 么?什么
- 将字符串转换为ASCII编码数组,只要是中文字节码就是ASCII编码63即"?",所以可以由此来进行判断class St
- 引言:最近在工作中遇到与某些API对接的post的数据需要将对象的字段首字母小写。解决办法有两种:第一种:使用对象的字段属性设置JsonPr
- 起源 [1946: John von Neumann, Stan Ulam, and Nick Metropolis, all a