地理编码节点 - 红色节点 - 谷歌。错误“无效请求。无效'latlng'参数”

时间:2017-08-20 16:19:42

标签: google-maps-api-3 geolocation geocoding node-red

我不是node-red的专家,真正感谢使用node-red-node-google地理编码节点的一些帮助。 link to Google Geolocation node-red node

我正在尝试使用上面提到的节点(坐标地理编码选项)从先前获得的坐标通过Google Geolocation API获取位置地址。我从外部应用程序通过POST获取纬度和长度。

如何将纬度和经度数据输入地理编码节点以获取正确的地址数据?经过数十次测试后,我总是得到同样的错误:“无效请求。无效'latlng'参数”。 我正在做的是:

  1. 通过POST生成的数据http://my_public_ip:1880/geo?id= {设备}& time = {time}& lat = {lat}& lng = {lng}& radius = {radius} 流的第一个节点是节点红色Http In节点,它实现htp端点,从该回调中获取信息。正确检索Te信息(请参阅调试输出): { “ID”: “18A834”, “时间”: “1503231980”, “LAT”: “40.xxxxxxxxxxxxxx”, “LNG”: “ - 3.xxxxxxxxxxxxxx”, “方圆”: “1651”} 注意:由隐私原因遮蔽的坐标。
  2. 如果来自HTTP In节点的lng和lat值被送入Google地理编码节点,则会收到消息错误“无效请求。无效'latlng'参数”。
  3. 我这样填写对话框:

    纬度文本框:msg.payload.lat

    经度文本框:msg.payload.lng

    1. 我已尝试插入coords函数节点的几个选项: 将纬度和经度值转换为浮点数,仅保留前7位小数,再次转换为字符串...,并始终收到相同的错误:“无效请求。无效'latlng'参数”
    2. coords功能节点配置:

      var coords ={};
      latitude= parseFloat(msg.payload.lat).toFixed(7);
      latitude1 = parseFloat(latitude);
      var length = parseFloat(msg.payload.lng).toFixed(7);
      var length1= parseFloat(length);
      coords.payload = {lat:latitude1, lng:length1};
      return coords;
      

      函数输出似乎是正确的: { “LAT”:40.xxxxxxx, “LNG”: - 3.xxxxxxx}

      所以我希望用msg.payload.lat填充文本框,并且msg.payload.lng应该没问题。显然有些不对劲......

      有人知道哪种方法可以将经度和纬度值提供给node-red-node-google google-geocoding以获得无误? 找到下面的节点红色代码(记住,还测试了不同类型的变量,并且根本没有测试任何功能):

      [{"id":"4dadb4d9.246a1c","type":"http in","z":"76138ea1.88752","name":"get_coords_from_post","url":"/geo","method":"get","upload":false,"swaggerDoc":"","x":300,"y":200,"wires":[["4a0b74fb.d10fcc","fb89b080.ef1cf","dac1b7ce.4cc2c8"]]},{"id":"fb89b080.ef1cf","type":"function","z":"76138ea1.88752","name":"coords","func":"var coords ={};\nlatitude= parseFloat(msg.payload.lat).toFixed(7);\nlatitude1 = parseFloat(latitude);\nvar length = parseFloat(msg.payload.lng).toFixed(7);\nvar length1= parseFloat(length);\ncoords.payload = {lat:latitude1, lng:length1};\nreturn coords; \n","outputs":1,"noerr":0,"x":510,"y":200,"wires":[["a24b08cf.22ebf8","dac1b7ce.4cc2c8"]]},{"id":"4a0b74fb.d10fcc","type":"http response","z":"76138ea1.88752","name":"","statusCode":"","headers":{},"x":484,"y":131,"wires":[]},{"id":"dac1b7ce.4cc2c8","type":"debug","z":"76138ea1.88752","name":"","active":true,"console":"false","complete":"false","x":990,"y":480,"wires":[]},{"id":"a24b08cf.22ebf8","type":"google geocoding","z":"76138ea1.88752","name":"find_address_from_coords","geocodeBy":"coordinates","address":"","lat":"msg.payload.lat","lon":"msg.payload.lng","googleAPI":"","bounds":"","language":"es","region":"","components":"","x":740,"y":200,"wires":[["dac1b7ce.4cc2c8"]]}]
      

1 个答案:

答案 0 :(得分:0)

您不应该在配置对话框中添加msg.payload.latmsg.payload.lon。如果要通过消息对象传递这些值,则需要在配置对话框中将它们留空。

接下来,如README.md和Node-RED中的信息栏所述,您需要在传入消息上设置msg.location.latmsg.location.lon以将这些值传递给节点。 / p>

所以基本上你的函数节点应该看起来更像这样:

var coords ={};
latitude= parseFloat(msg.payload.lat).toFixed(7);
latitude1 = parseFloat(latitude);
var length = parseFloat(msg.payload.lng).toFixed(7);
var length1= parseFloat(length);
coords.location = {lat:latitude1, lon:length1};
return coords;