jpmobileによる位置情報取得サンプル
jpmobileを使って現在位置のテキスト情報を表示するだけの超単純なサンプルを作りました。ガラケーで以下のQRコードを読み取って位置情報を送信すると、おおよその世界測地系の緯度・経度と住所(都道府県、市区町村、町丁目番地)を返します。
住所はGeokitプラグインを使って緯度と経度から求めてます。FireMobileSimulatorと実機でdocomoとauの確認はしましたが、softbankは確認してません。またiPhoneなどからは利用出来ません。
【以下サンプルコード】
・get_position_controller.rb
class GetPositionController < ApplicationController include GeoKit::Geocoders def index end def gps @pos = request.mobile.position @pos.tokyo2wgs84! #日本測地系から世界測地系へ変換 tmp = Geokit::Geocoders::GoogleGeocoder.reverse_geocode sprintf("%f,%f",@pos.lat,@pos.lon) @res = tmp.state,tmp.city,tmp.district,tmp.street_address end end
・index.html.erb
<%= get_position_link_to "位置情報の取得", :action => :gps %>
・gps.html.erb
緯度:<%= @pos.lat %>
経度:<%= @pos.lon %>
住所:<%= @res %>
【参考】