如何创建用于查询Google Browserlocation的脚本

时间:2015-06-22 05:19:20

标签: json google-api

我正试图找出一种从Google的浏览器位置API获取地理位置数据的方法。我找到了JSON, CURL and Google's geolocation,并让它工作到范围内的接入点列表,但我的有限cli-fu将不允许我将其解析为我可以发送给Google的内容。

到目前为止,我有

nmcli -f SSID,BSSID,SIGNAL  dev wifi list
SSID             BSSID              SIGNAL 
ElisaKoti73      00:0C:C3:7F:7E:64  66     
Kanala           00:1E:AB:56:84:3F  65     
TW-EAV510v236E3  00:1E:AB:09:36:E4  44     
WLAN-AP          00:1E:AB:04:C5:C5  32     
meduusan verkko  00:1E:AB:54:C4:E0  25     
Koti_E8BC        EE:43:F6:99:E8:BC  22     
Inteno_E1        00:22:07:13:6A:E0  19

我现在要将其转化为类似

的内容
https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true&
wifi=mac:00:0C:C3:7F:7E:64|ssid:ElisaKoti73|ss:66&

编辑:根据@hotmultimedia的答案进行调整,我得到了     

curl "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true&" --data-urlencode "`nmcli -f SSID,BSSID,SIGNAL dev wifi list |perl -ne "if(s/^(.+?)\s+(..:..:..:..:..:..)\s+(.+?)\s*$/&wifi=mac:\2|ssid:\1|ss:\3&/g){print;}"`"

现在这样可行,但准确性已经过时了:curl "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true&" --data-urlencode "`nmcli -f SSID,BSSID,SIGNAL dev wifi list |perl -ne "if(s/^(.+?)\s+(..:..:..:..:..:..)\s+(.+?)\s*$/&wifi=mac:\2|ssid:\1|ss:\3&/g){print;}"`"。令人费解的是,如果我在浏览器中复制粘贴相同的地址,则返回的JSON非常精确,准确度为"accuracy" : 11178。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

以下是如何使用(略微非最佳:) Perl oneliner完成此转换:

perl -ne "if(s/^(.+?)\s+(..:..:..:..:..:..)\s+(.+?)\s*$/https:\/\/maps.googleapis.com\/maps\/api\/browserlocation\/json?browser=firefox&sensor=true&wifi=mac:\2|ssid:\1|ss:\3&\n/g){print;}"