具有大数据的地热图(google) [英] Geo heat map(google) with large data

查看:137
本文介绍了具有大数据的地热图(google)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 google地图中绘制一个热图,以显示城市的出租车出租车分布.

I want to plot a heat map in google map to show the taxi-ride distribution of a city.

我获得了出租车行驶开始位置(纬度和经度)的 4000个数据.

I got around 4000 data of the taxi-ride starting location(latitude and longitude).

以下是我的一些脚本:

首先,我设置了Google地图:

First I set up the google map:

var hongkong = new google.maps.LatLng(22.28552,114.15769 );

map = new google.maps.Map(document.getElementById('map'), {
    center: hongkong,
    zoom: 11,
 });

然后,我从JSON文件中读取数据并创建一个热图:

Then, I read the data from JSON file and make a heat map:

jQuery.getJSON("data.json", function(data) {
    var heatmapData = [];
    jQuery.each(data, function(key, val) {
          heatmapData.push(new google.maps.LatLng(val.fromLocation.lat, val.fromLocation.lng));
    });

    var heatmap = new google.maps.visualization.HeatmapLayer({
          data: heatmapData
    });
    heatmap.setMap(map);
});


我得到了什么:


What I got:

您什么也看不到.然后缩小,我得到:

You can see nothing. Then I zoom out, I got:

期望是这样的:

出什么问题了?是我得到的数据太接近了吗?

What is the problem? Is it the data I got is too close to each other?

是否有更好的方法绘制热图以显示出租车的分布情况?谢谢.

Is there a better way to plot the heat map to show the distribution of taxi-riding? Thank you.

推荐答案

您的JSON文件已将纬度和经度作为字符串. Google的 LatLng 构造函数希望这些值是数字.试试这个,将它们从像"22.37898"这样的字符串转换成像22.37898

Your JSON file has got the latitudes and longitudes as strings. Google's LatLng constructor expects those values to be numbers. Try this, which converts them from strings like "22.37898" to floats like 22.37898

heatmapData.push(new google.maps.LatLng(
    parseFloat(val.fromLocation.lat), 
    parseFloat(val.fromLocation.lng))
);

这篇关于具有大数据的地热图(google)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆