Geo heat map(google) with large data

岁酱吖の 提交于 2019-12-10 23:19:59

问题


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

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

Here are some of my script:

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,
 });

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 I expected is something like this:

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.


回答1:


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))
);


来源:https://stackoverflow.com/questions/39432823/geo-heat-mapgoogle-with-large-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!