gpt4 book ai didi

javascript - 带有 geohash 的谷歌图表

转载 作者:行者123 更新时间:2023-11-30 15:31:43 26 4
gpt4 key购买 nike

您好,我正在使用 googleCharts https://developers.google.com/chart/interactive/docs/gallery/geochart我需要将 GeoHash 设置到列中进行绘制,但我尝试了,目前确实有效有了经纬度,它的作品

  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/script.js"></script>
<script type="text/javascript">
google.charts.load('upcoming', {'packages': ['geochart']});
google.charts.setOnLoadCallback(drawMarkersMap);

function drawMarkersMap() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'Latitude');
data.addColumn('number', 'Longitude');
data.addColumn('string', 'Label');
data.addColumn('number', 'Value 1');
data.addColumn('number', 'Value 2');

data.addRows([
[-22.764042, -43.39921, 'Foo', 2.86, 4],
[-22.755635, -43.460325, 'Bar', 5, 2],
[-22.912897, -43.200295, 'Baz', 0.50, 1],
[-22.805776, -43.37292, 'Cad', 6.67, 2],
[-23.532905, -46.63952, 'Qud', 33.33, 5]
]);
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, {
width: 600,
region: 'BR',//rgiomn
colorAxis: {colors: ['green', 'blue']} //color de transicion


});

};
</script>

但是如果我尝试使用 geohash ,请在控制台中显示此错误:

drawMarkersMap — cargamapa:72ReferenceError: Can't find variable: gbsuv

我的变量

  data.addRows([
['gbsuv', 'Foo', 2.86, 4],
['gbsuv', 'Bar', 5, 2],
['gbtst' 'Baz', 0.50, 1],

]);

最佳答案

请分享变量的值...

gbsuv, gbtst, gbtse

如果它们是数组([]),那么尝试...

data.addRows([
[gbsuv[0], gbsuv[1], 'Foo', 2.86, 4],
[gbsuv[0], gbsuv[1], 'Bar', 5, 2],
[gbtst[0], gbtst[1], 'Baz', 0.50, 1],
[gbtse[0], gbtse[1], 'Cad', 6.67, 2]
]);

编辑

data format因为 map 可视化不支持 geohash

Two data formats are supported:

1. Lat-Long pairs - The first two columns should be numbers designating the latitude and longitude, respectively. An optional third column holds a string that describes the location specified in the first two columns.

2. String address - The first column should be a string that contains an address. This address should be as complete as you can make it. An optional second column holds a string that describes the location in the first column. String addresses load more slowly, especially when you have more than 10 addresses.

但是,您可以使用诸如...之类的库来解码 geohash

latlon-geohash.js

调用函数 --> Geohash.decode(geohash)
将返回具有 latlon

属性的对象
var gbsuv = Geohash.decode('gbsuv');

data.addRows([
[gbsuv.lat, gbsuv.lon, 'Foo', 2.86, 4],
...
]);

关于javascript - 带有 geohash 的谷歌图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42160217/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com