【Android】3.10 热力图功能
分类: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 热力图功能的更多相关文章
- 调用Android自带日历功能(日历列表单、添加一个日历事件)
调用Android自带日历功能 觉得这篇文章不错,转载过来. 转载:http://blog.csdn.net/djy1992/article/details/9948393 Android手机配备有 ...
- Android Webview实现文件下载功能
在做美图欣赏Android应用的时候,其中有涉及到Android应用下载的功能,这个应用本身其实也比较简单,就是通过WebView控制调用相应的WEB页面进行展示.刚开始以为和普通的文件下载实 ...
- I.MX6 android 移除shutdown功能
/************************************************************************ * I.MX6 android 移除shutdown ...
- 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 ...
- 你真的有必要退出吗——再说Android程序的退出功能
转自你真的有必要退出吗--再说Android程序的退出功能 搞Android开发有一段时间了,相信很多从Windows开发过来的Android程序员都习惯性地会跟我一样遇到过同一个问题:如何彻底退出程 ...
- Android使得手机拍照功能的发展(源共享)
Android系统调用手机拍照功能有两种方法来直接调用手机自带摄像头还有一个就是要当心自己的节拍. 例Camera360 强大的一个在每个操作系统都有一个手机摄影软件:您可以捕捉不同风格,不同特效的照 ...
- Android实现自动更新功能
Android实现自动更新功能 Android自动更新的功能可以使用第三方的SDK来实现,但是类似友盟,就不支持x86手机的自动更新,科大讯飞,弹窗是全局的,小米手机就会默认把弹窗权限关掉不允许弹出提 ...
- Android Camera2 预览功能实现
1. 概述 最近在做一些关于人脸识别的项目,需要用到 Android 相机的预览功能.网上查阅相关资料后,发现 Android 5.0 及以后的版本中,原有的 Camera API 已经被 Camer ...
- 微软已发布 Windows 10 Timeline 功能的官方 Chrome 插件
微软已发布 Windows 10 Timeline 功能的官方 Chrome 插件,这个插件名为 Web Activities,功能是跨 Windows 10 和 Microsoft Launcher ...
随机推荐
- data directory "/var/lib/postgres/data" has group or world access
直接拷贝完好的data至pg目录底下,可能引起下面的错误:说data目录权限不是700.FATAL: data directory "/var/lib/postgres/data" ...
- c#实现验证码功能(多种模式下分别实现验证功能)详细,带注释
网上找了很多验证相关的代码,发现有很多瑕疵.现在本人整理测试了一个实现验证码功能的代码,里面有纯数字,纯英文,英文和数字混合等三种模式.并且在必要地方都已经备有注释,希望可以帮到那些需要的人. 验证码 ...
- 使用javacv录像,同时进行讯飞声纹认证
由于最近的demo中需要在活体检测的同时进行音视频录制 , 尝试使用MediaRecord和camera来录制视频 , 然而Camera.onPreviewFrame 不能与 MediaRecord ...
- TopCoder SRM624 BuildingHeightEasy 题解
本题题意就是求有一组建筑物,问把这些建筑物的M个都统一到同一高度.须要的最小改动高度是多少? 题意隐含的意思就是由于是建筑物,所以不能降低,仅仅能添加了. 本题能够使用暴力搜索,由于数据量少. 可是事 ...
- 解决vsftpd乱码
不管是中文环境还是英文环境,需要改的地方如下: /etc/sysconfig/i18n 其内容改为: LANG="zh_CN.GB2312"SYSFONT="latarc ...
- java数组转json
public String toJsonObject(String[] list) { String json="["; for (int i=0;i<list.length ...
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed w ...
- 1、redis之安装与配置
下载安装: redis-server.exe redis服务器的daemon启动程序 redis.conf redis配置文件 redis-cli.exe redis命令行操作工具.当然,也可以用te ...
- A. Dreamoon and Stairs(Codeforces Round #272)
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- MyEclipse上的第一个java web
简单解说怎样MyEclipse上开发一个web project 以及怎样部署的问题. 第一步: 创建一个web project File -> New -> Web Project 将出现 ...