LoginSignup
3
3

More than 5 years have passed since last update.

GoogleLatitudeの公開バッジから現在の位置情報を取得する

Last updated at Posted at 2012-05-29

GoogleLatitudeのブログパーツとして公開バッジを使うように設定しているユーザーの情報だけ取れる。
公開設定にすると誰でも現在地を取れるようになるので注意(or覚悟?)が必要

latitude.rb
require 'open-uri'
require 'json'
# https://www.google.com/latitude/apps にjson apiのURLが書いてある。そこからIDを抜き出す
yuiseki = '4598697423011019361'
badge = "https://www.google.com/latitude/apps/badge/api?user=#{yuiseki}&type=json"
data = JSON.parse(open(badge).read())

# 精度
acrcy = data['features'].first['properties']['accuracyInMeters']
time = data['features'].first['properties']['timeStamp']
icon = data['features'].first['properties']['photoUrl']
lat = data['features'].first['geometry']['coordinates'][0]
lng = data['features'].first['geometry']['coordinates'][1]
# だいたいの住所もとれる
rgeo = data['features'].first['properties']['reverseGeocode']
puts rgeo

# Google Static Maps APIで500x100の静止画像にしてみる例
map = "http://maps.google.com/maps/api/staticmap?"+
      "center=#{lng},#{lat}" +
      "&zoom=15&size=500x100&sensor=false" +
      "&markers=icon:#{icon}|#{lng},#{lat}"
puts map

オマケ
ぼくの公開バッジ用JSON APIだと、
https://www.google.com/latitude/apps/badge/api?user=4598697423011019361&type=json
こういうJSON構造になっている

{
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      geometry: {
        type: "Point",
        coordinates: [
          139.7675734,
          35.7011698
        ]
      },
      properties: {
        id: "4598697423011019361",
        accuracyInMeters: 42,
        timeStamp: 1338202878,
        reverseGeocode: "日本, 東京都千代田区",
        photoUrl: "https://www.google.com/latitude/apps/badge/api?type=photo&photo=WZImkzcBAAA.Q47_7dfAqny0ALmGvVcg1w.ZDejmc8WR9myfjUomKHszQ",
        photoWidth: 96,
        photoHeight: 96,
        placardUrl: "https://www.google.com/latitude/apps/badge/api?type=photo_placard&photo=WZImkzcBAAA.Q47_7dfAqny0ALmGvVcg1w.ZDejmc8WR9myfjUomKHszQ&moving=true&stale=true&lod=1&format=png",
        placardWidth: 56,
        placardHeight: 59
      }
    }
  ]
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3