分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

一、简介

热力图是用不同颜色的区块叠加在地图上描述人群分布、密度和变化趋势的一个产品,可利用自有数据,构建属于自己的热力图,为用户提供丰富的展示效果。

二、运行截图

简介:绘制自有数据热力图

详述:

(1)设置热力图颜色;

(2)准备数据、生成热力图;

(3)删除热力图;

本示例运行截图如下:

注意:由于.json文件包含的是全国范围的数据,单线程的加载过程非常慢(约10分钟左右),需要耐心等待。一旦数据加载完毕,再进行添加、删除操作就很快了。

当【添加】按钮变为可用时,单击它即可看到截图的效果。

三、设计步骤

1、添加demo10_heatmap.xml文件

在layout文件夹下添加该文件,然后将代码改为下面的内容:

<?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" > <Button
android:id="@+id/add"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:padding="10dip"
android:text="添加" /> <Button
android:id="@+id/remove"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dip"
android:layout_weight="1"
android:text="删除" />
</LinearLayout> <com.baidu.mapapi.map.TextureMapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </LinearLayout>

2、添加Demo10HeatMap.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将代码改为下面的内容:

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Widget;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
using System.Collections.Generic;
using System.Threading.Tasks; namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 热力图功能demo
/// </summary>
[Activity(Label = "@string/demo_name_heatmap",
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
ScreenOrientation = ScreenOrientation.Sensor)]
public class Demo10HeatMap : Activity
{
private TextureMapView mMapView;
private BaiduMap mBaiduMap;
private HeatMap heatmap;
private Button mAdd;
private Button mRemove;
private bool isDestroy; private List<LatLng> data; protected async override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.demo10_heatmap); mMapView = FindViewById<TextureMapView>(Resource.Id.mapview);
mBaiduMap = mMapView.Map;
mBaiduMap.SetMapStatus(MapStatusUpdateFactory.ZoomTo()); mAdd = FindViewById<Button>(Resource.Id.add);
mRemove = FindViewById<Button>(Resource.Id.remove);
mAdd.Enabled = false;
mRemove.Enabled = false;
mAdd.Click += delegate
{
AddHeatMap();
};
mRemove.Click += delegate
{
heatmap.RemoveHeatMap();
mAdd.Enabled = true;
mRemove.Enabled = false;
}; await Task.Run(() =>
{
data = new List<LatLng>();
var stream = Resources.OpenRawResource(Resource.Raw.locations);
string json = new Java.Util.Scanner(stream).UseDelimiter("\\A").Next();
try
{
Org.Json.JSONArray array = new Org.Json.JSONArray(json);
for (int i = ; i < array.Length(); i++)
{
Org.Json.JSONObject obj = array.GetJSONObject(i);
double lat = obj.GetDouble("lat");
double lng = obj.GetDouble("lng");
data.Add(new LatLng(lat, lng));
}
}
catch (Java.Lang.Exception e)
{
e.PrintStackTrace();
}
});
mAdd.Enabled = true;
} private void AddHeatMap()
{
mAdd.Enabled = false;
heatmap = new HeatMap.Builder().Data(data).Build();
if (!isDestroy)
{
mBaiduMap.AddHeatMap(heatmap);
}
mRemove.Enabled = true;
} protected override void OnPause()
{
base.OnPause();
mMapView.OnPause();
} protected override void OnResume()
{
base.OnResume();
mMapView.OnResume();
} protected override void OnDestroy()
{
base.OnDestroy();
isDestroy = true;
mMapView.OnDestroy();
}
}
}

3、修改MainActivity.cs

在MainActivity.cs文件的demos字段定义中,去掉【示例10】下面的注释。

运行观察结果。

【Android】3.10 热力图功能的更多相关文章

  1. 调用Android自带日历功能(日历列表单、添加一个日历事件)

    调用Android自带日历功能  觉得这篇文章不错,转载过来. 转载:http://blog.csdn.net/djy1992/article/details/9948393 Android手机配备有 ...

  2. Android Webview实现文件下载功能

        在做美图欣赏Android应用的时候,其中有涉及到Android应用下载的功能,这个应用本身其实也比较简单,就是通过WebView控制调用相应的WEB页面进行展示.刚开始以为和普通的文件下载实 ...

  3. I.MX6 android 移除shutdown功能

    /************************************************************************ * I.MX6 android 移除shutdown ...

  4. Xamarin.Android 4.10.01068 & Xamarin.iOS 1.8.361

    Xamarin.Android 4.10.01068 & Xamarin.iOS 1.8.361 NEW support for Visual Studio 2013 & Portab ...

  5. 你真的有必要退出吗——再说Android程序的退出功能

    转自你真的有必要退出吗--再说Android程序的退出功能 搞Android开发有一段时间了,相信很多从Windows开发过来的Android程序员都习惯性地会跟我一样遇到过同一个问题:如何彻底退出程 ...

  6. Android使得手机拍照功能的发展(源共享)

    Android系统调用手机拍照功能有两种方法来直接调用手机自带摄像头还有一个就是要当心自己的节拍. 例Camera360 强大的一个在每个操作系统都有一个手机摄影软件:您可以捕捉不同风格,不同特效的照 ...

  7. Android实现自动更新功能

    Android实现自动更新功能 Android自动更新的功能可以使用第三方的SDK来实现,但是类似友盟,就不支持x86手机的自动更新,科大讯飞,弹窗是全局的,小米手机就会默认把弹窗权限关掉不允许弹出提 ...

  8. Android Camera2 预览功能实现

    1. 概述 最近在做一些关于人脸识别的项目,需要用到 Android 相机的预览功能.网上查阅相关资料后,发现 Android 5.0 及以后的版本中,原有的 Camera API 已经被 Camer ...

  9. 微软已发布 Windows 10 Timeline 功能的官方 Chrome 插件

    微软已发布 Windows 10 Timeline 功能的官方 Chrome 插件,这个插件名为 Web Activities,功能是跨 Windows 10 和 Microsoft Launcher ...

随机推荐

  1. Hibernate(十四)缓存

    一.什么是缓存 缓存是介于应用程序和永久必数据存储源之间,目的是为了降低应用程序直接读写永久必数据存储源的频率,从而提高运行性能 缓存通常是在内存中的如: Office中的Word.excel Hib ...

  2. MySQL单列索引和组合索引(联合索引)的区别详解

    发现index merge局限性,优化器会自动判断是否使用 index merge 优化技术,查询还是需要组合索引[推荐阅读:对mysql使用索引的误解] MySQL单列索引和组合索引(联合索引)的区 ...

  3. ng-src 的坑

    问题: <ion-slide ng-repeat="item in bannrImgData" ng-click="getActivity($index)" ...

  4. HTTP Header具体解释

    HTTP(HyperTextTransferProtocol) 即超文本传输协议,眼下网页传输的的通用协议.HTTP协议採用了请求/响应模型,浏览器或其它client发出请求.server给与响应.就 ...

  5. doGet和doPost区别

    1,form运行方式 当form框里面的method为get时,执行doGet方法当form框里面的method为post时,执行doPost方法 2,生成方式 get方式有四种:1)直接在URL地址 ...

  6. 数据挖掘之权重计算(PageRank)

    刘  勇  Email:lyssym@sina.com 简介 鉴于在Web抓取服务和文本挖掘之句子向量中对权重值的计算需要,本文基于MapReduce计算模型实现了PageRank算法.为验证本文算法 ...

  7. TouchID 指纹解锁

    概述 TouchID 指纹解锁 详细 代码下载:http://www.demodashi.com/demo/10701.html 一.软硬件支持 指纹验证功能的最低硬件支持为iPhone5s, iPa ...

  8. (二)Activiti之——activiti数据库表介绍

    1. 数据库表的命名 Activiti的表都以ACT_开头. 第二部分是表示表的用途的两个字母标识. 用途也和服务的API对应. ACT_RE_*: 'RE'表示repository. 这个前缀的表包 ...

  9. Centos下cacti的安装

    介绍 Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形.它提供了非常强大的数据和 ...

  10. PHP开发安全问题

    1.不相信表单 对于一般的Javascript前台验证,由于无法得知用户的行为,例如关闭了浏览器的javascript引擎,这样通过POST恶意数据到服务器.需要在服务器端进行验证,对每个php脚本验 ...