代码之家  ›  专栏  ›  技术社区  ›  MAB

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

  •  0
  • MAB  · 技术社区  · 7 年前

    我不是node red的专家,非常感谢大家对使用node red node google geocoding node的帮助。 link to Google Geolocation node-red node

    我正试图通过谷歌地理定位API从之前使用上述节点获得的坐标中获取位置地址(按坐标进行地理编码选项)。我通过POST从外部应用程序获取纬度和长度。

    纬度和经度数据应该如何输入地理代码节点以获得正确的地址数据?经过几十次测试,我总是得到相同的错误:“无效的请求。无效的‘latlng’参数”。 我正在做的是:

    1. http://my_public_ip:1880/geo?id= {device}&时间={time}&lat={lat}&液化天然气={lng}&半径={radius} 流的第一个节点是一个节点红色Http In节点,它实现了htp端点,从该回调中获取信息。正确检索Te信息(请参阅调试输出): {“id”:“18A834”,“time”:“1503231980”,“lat”:“40.xxxxxxxxxxxx”,“lng”:“-3.xxxxxxxxxxxxx”,“radius”:“1651”} 注意:由于隐私原因,坐标会受到影响。
    2. 如果来自HTTP In节点的lng和lat值被送入谷歌地理编码节点,则会收到错误消息“请求无效。latlng参数无效”。

    我这样填充对话框:

    1. 我尝试了几种插入coords功能节点的选项:

    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}

    有人知道哪种方法是正确的,可以将经度和纬度值提供给节点red node 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 回复  |  直到 7 年前
        1
  •  0
  •   hardillb    7 年前

    你不应该把 msg.payload.lat msg.payload.lon 在配置对话框中。如果要通过消息对象传递这些值,则需要在配置对话框中将其留空。

    接下来,如自述中所述。md和红色节点中的信息栏,您需要设置 msg.location.lat msg.location.lon

    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;