如何使用javascript从couchdb获取数据

时间:2022-09-25 23:34:49

I have store some document in couchdb, and generate a view using map reduce. Every document in the view is in following structure :

我在couchdb中存储了一些文档,并使用map reduce生成一个视图。视图中的每个文档都具有以下结构:

{user_name, longitude, latitude, tweet_content} 

Now I need to use the api of google map to show these point. (The heatmap) I need to get the value of longitude and latitude in the that view in couchdb. The google map provide the HTML code to show the heatmap, (https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap) I just need the data of coordination. The problems seems like how to use Javascript to connect with couchdb. I just have no idea about how to get start, and cannot find any instruction about how to write the Javascript code in HTML.

现在我需要使用谷歌地图的api来显示这一点。 (热图)我需要在couchdb中的该视图中获取经度和纬度的值。谷歌地图提供了显示热图的HTML代码,(https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap)我只需要协调数据。问题似乎是如何使用Javascript连接couchdb。我根本不知道如何开始,也找不到任何关于如何用HTML编写Javascript代码的说明。

2 个解决方案

#1


The heatmap code you have referred to will be executed client-side in the browser.

您引用的热图代码将在浏览器中的客户端执行。

I just have no idea about how to get start, and cannot find any instruction about how to write the Javascript code in HTML.

我根本不知道如何开始,也找不到任何关于如何用HTML编写Javascript代码的说明。

The JavaScript code can be included into your HTML in several ways. Start by reading about the HTML script tag.

JavaScript代码可以通过多种方式包含在HTML中。首先阅读HTML脚本标记。

The problems seems like how to use Javascript to connect with couchdb.

问题似乎是如何使用Javascript连接couchdb。

Once your HTML content is loaded in the browser you can communicate with CouchDB via AJAX calls

在浏览器中加载HTML内容后,您就可以通过AJAX调用与CouchDB进行通信

#2


$.ajax({
      url: 'http://name:password@localhost:5984/yourdatabase/_design/analyse/_view/viewname',
      type: 'get',
      dataType: 'json',
      success: function(data) {
        data.rows.forEach(function(tweet){

          taxiData.push(new google.maps.LatLng(tweet.key[0], tweet.key[1]))
          console.log(tweet.key[0]);
        });
      },
      reduce: false
    });

#1


The heatmap code you have referred to will be executed client-side in the browser.

您引用的热图代码将在浏览器中的客户端执行。

I just have no idea about how to get start, and cannot find any instruction about how to write the Javascript code in HTML.

我根本不知道如何开始,也找不到任何关于如何用HTML编写Javascript代码的说明。

The JavaScript code can be included into your HTML in several ways. Start by reading about the HTML script tag.

JavaScript代码可以通过多种方式包含在HTML中。首先阅读HTML脚本标记。

The problems seems like how to use Javascript to connect with couchdb.

问题似乎是如何使用Javascript连接couchdb。

Once your HTML content is loaded in the browser you can communicate with CouchDB via AJAX calls

在浏览器中加载HTML内容后,您就可以通过AJAX调用与CouchDB进行通信

#2


$.ajax({
      url: 'http://name:password@localhost:5984/yourdatabase/_design/analyse/_view/viewname',
      type: 'get',
      dataType: 'json',
      success: function(data) {
        data.rows.forEach(function(tweet){

          taxiData.push(new google.maps.LatLng(tweet.key[0], tweet.key[1]))
          console.log(tweet.key[0]);
        });
      },
      reduce: false
    });