当前位置: 移动技术网 > IT编程>移动开发>Android > Android百度地图应用之图层展示

Android百度地图应用之图层展示

2019年07月24日  | 移动技术网IT编程  | 我要评论

呱呱蔡贵霖,旦宁博,ccbupt

一、简介
 1、地图类型
 百度地图android sdk 3.7.1提供了两种类型的地图资源(普通矢量地图和卫星图),开发者可以利用baidumap中的maptype属性(c#)来设置地图类型。c#核心代码如下: 

mmapview = findviewbyid<texturemapview>(resource.id.bmapview);
mbaidumap = mmapview.map;
//设置底图显示模式:普通地图
mbaidumap.maptype = baidumap.maptypenormal;
//设置底图显示模式:卫星地图
mbaidumap.maptype = baidumap.maptypesatellite; 

2、实时交通图
 当前,全国范围内已支持多个城市实时路况查询,且会陆续开通其他城市。 
目前有哪些城市具有实时交通图? 
目前(2016-01-27)已有31个城市开通,分别为南京,广州,重庆,东莞,长春,台州,福州,金华,北京,常州,杭州,温州,大连,南昌,宁波,沈阳,中山,珠海,佛山,泉州,石家庄,成都,青岛,深圳,武汉,乌鲁木齐,长沙,上海,天津,无锡,厦门。之后其他城市还会陆续开通。
 在地图上打开实时路况的c#核心代码如下: 

mmapview = findviewbyid<texturemapview>(resource.id.bmapview);
mbaidumap = mmapview.map;
//开启交通图
mbaidumap.trafficenabled = true; 

3、百度城市热力图
 百度地图sdk继为广大开发者开放热力图本地绘制能力之后,再次进一步开放百度自有数据的城市热力图层,帮助开发者构建形式更加多样的移动端应用。 
百度城市热力图的性质及使用与实时交通图类似,只需要简单的接口调用,即可在地图上展现样式丰富的百度城市热力图。 
在地图上开启百度城市热力图的c#核心代码如下: 

mmapview = findviewbyid<texturemapview>(resource.id.bmapview);
mbaidumap = mmapview.map;
//开启交通图
mbaidumap.baiduheatmapenabled = true;


在上一节例子的基础上,只需要再增加下面的步骤即可。
 1、添加demo04_layers.axml文件

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <linearlayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <radiogroup
      android:id="@+id/radiogroup"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="2"
      android:orientation="horizontal" >

      <radiobutton
        android:id="@+id/normal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="普通图" />

      <radiobutton
        android:id="@+id/statellite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="卫星图" />
    </radiogroup>

    <checkbox
      android:id="@+id/traffice"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:checked="false"
      android:text="交通图" />
     
     <checkbox
      android:id="@+id/baiduheatmap"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:checked="false"
      android:text="百度城市热力图" />
  </linearlayout>

  <com.baidu.mapapi.map.texturemapview
    android:id="@+id/bmapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true" />

</linearlayout>

2、添加demo04layers.cs文件 
在srcsdkdemos文件夹下添加该文件。

using android.app;
using android.content.pm;
using android.os;
using android.widget;
using com.baidu.mapapi.map;

namespace bdmapv371demos.srcsdkdemos
{
  /// <summary>
  /// 演示地图图层显示的控制方法
  /// </summary>
  [activity(label = "@string/demo_name_layers",
    configurationchanges = configchanges.orientation | configchanges.keyboardhidden,
    screenorientation = screenorientation.sensor)]
  public class demo04layers : activity
  {
    //texturemapview 是地图主控件
    private texturemapview mmapview;
    private baidumap mbaidumap;

    protected override void oncreate(bundle savedinstancestate)
    {
      base.oncreate(savedinstancestate);
      setcontentview(resource.layout.demo04_layers);

      mmapview = findviewbyid<texturemapview>(resource.id.bmapview);
      mbaidumap = mmapview.map;
      mbaidumap.setmapstatus(mapstatusupdatefactory.newlatlng(mainactivity.henanuniversity));

      //设置底图显示模式:普通图
      var normal = findviewbyid<radiobutton>(resource.id.normal);
      normal.click += delegate
      {
        mbaidumap.maptype = baidumap.maptypenormal;
      };

      //设置底图显示模式:卫星图
      var statellite = findviewbyid<radiobutton>(resource.id.statellite);
      statellite.click += delegate
      {
        mbaidumap.maptype = baidumap.maptypesatellite;
      };

      //是否显示交通图
      var traffice = findviewbyid<checkbox>(resource.id.traffice);
      traffice.checkedchange += (s, e) =>
      {
        mbaidumap.trafficenabled = e.ischecked;
      };

      //是否显示热力图
      var baiduheatmap = findviewbyid<checkbox>(resource.id.baiduheatmap);
      traffice.checkedchange += (s, e) =>
      {
        mbaidumap.baiduheatmapenabled = e.ischecked;
      };
    }

    protected override void onpause()
    {
      mmapview.onpause();
      base.onpause();
    }

    protected override void onresume()
    {
      mmapview.onresume();
      base.onresume();
    }

    protected override void ondestroy()
    {
      mmapview.ondestroy();
      base.ondestroy();
    }
  }
}

4、修改mainactivity.cs文件
 在mainactivity.cs文件的demos字段定义中添加下面的代码。    

     //示例4--图层展示
      new demoinfo<activity>(resource.string.demo_title_layers,
        resource.string.demo_desc_layers,
        new demo04layers()),

 运行。

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网