10月062012
0
なんとなくgithub page作った
Wifi location – Get your location with WiFi Mac Address and GoogleMap.
github page楽すぎる
前記事:Mac/LinuxのWiFiで位置情報を取得
なんとなくgithub page作った
Wifi location – Get your location with WiFi Mac Address and GoogleMap.
github page楽すぎる
前記事:Mac/LinuxのWiFiで位置情報を取得
wifi_locationというrubygemを作った。Mac (Lion, Mountain Lion)と Ubuntu 12.04で動く。
gem install wifi_locationwhereamiというコマンドが付属してるので、これを使うと
whereami --help
whereami --dump
{"towers":[{"bssid":"20:f3:a3:8c:66:ab","signal":-72},{"bssid":"00:0a:79:a5:7c:16","signal":-80},{"bssid":"1c:b1:7f:11:f8:c2","signal":-82},{"bssid":"20:f3:a3:32:58:f7","signal":-91},{"bssid":"の","signal":0},{"bssid":"00:24:a5:b8:90:e7","signal":-80},{"bssid":"10:c6:1f:ec:f8:49","signal":-56}],"location":{"latitude":35.640688,"longitude":139.6941365,"address":{"country":"日本","country_code":"JP","region":"東京都","city":"目黒区","street":"1丁目","street_number":"1"},"accuracy":40.0}}こういうのが出てくる。
gem install wifi_location
#!/usr/bin/env rubyWiFiLocation.locationが返すhashに、緯度経度住所番地国名などなどが入っている。
require 'rubygems'
require 'wifi_location'
loc = WiFiLocation.location
puts "#{loc['latitude']}, #{loc['longitude']}"
p loc
*/5 * * * * ruby -e 'puts "#{Time.now.to_i}\t#{`whereami --towers`}"' >> ~/wifi-towers.txtとか書いておく。5分毎に~/wifi-towers.txt にunixtimeと電波状況が保存される。
cat ~/wifi-towers.txt | ruby -rjson -rwifi_location -lane 'a=$_.split(/\t/); time = Time.at a[0].to_i; loc = WiFiLocation.location JSON.parse a[1]; puts "#{time}\t#{loc.inspect}"'
2012-08-03 20:05:00 +0900 {"latitude"=>35.5470762, "longitude"=>139.6434858, "address"=>{"country"=>"日本", "country_code"=>"JP", "region"=>"神奈川県", "city"=>"横浜市", "street"=>"3丁目", "street_number"=>"14"}, "accuracy"=>45.0}
2012-08-03 20:10:00 +0900 {"latitude"=>35.5823082, "longitude"=>139.663203, "address"=>{"country"=>"日本", "country_code"=>"JP", "region"=>"神奈川県", "city"=>"川崎市", "street"=>"1丁目", "street_number"=>"667"}, "accuracy"=>49.0}
2012-08-03 20:15:00 +0900 {"latitude"=>35.69384, "longitude"=>139.703549, "address"=>{"country"=>"日本", "country_code"=>"JP", "region"=>"東京都", "city"=>"新宿区", "street"=>"1丁目", "street_number"=>"4"}, "accuracy"=>166000.0}