我不是node-red的专家,真正感谢使用node-red-node-google地理编码节点的一些帮助。 link to Google Geolocation node-red node
我正在尝试使用上面提到的节点(坐标地理编码选项)从先前获得的坐标通过Google Geolocation API获取位置地址。我从外部应用程序通过POST获取纬度和长度。
如何将纬度和经度数据输入地理编码节点以获取正确的地址数据?经过数十次测试后,我总是得到同样的错误:“无效请求。无效'latlng'参数”。 我正在做的是:
我这样填写对话框:
纬度文本框:msg.payload.lat
经度文本框:msg.payload.lng
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"]]}]
答案 0 :(得分:0)
您不应该在配置对话框中添加msg.payload.lat
或msg.payload.lon
。如果要通过消息对象传递这些值,则需要在配置对话框中将它们留空。
接下来,如README.md和Node-RED中的信息栏所述,您需要在传入消息上设置msg.location.lat
和msg.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;