瀏覽代碼

Added start of custom response for Layar

master
Adrian Short 12 年之前
父節點
當前提交
360587a1ad
共有 3 個文件被更改,包括 28 次插入1 次删除
  1. +12
    -1
      app/controllers/posts_controller.rb
  2. +14
    -0
      app/helpers/posts_helper.rb
  3. +2
    -0
      config/initializers/mime_types.rb

+ 12
- 1
app/controllers/posts_controller.rb 查看文件

@@ -1,10 +1,21 @@
class PostsController < ApplicationController
include PostsHelper
def near
@posts = Post.near(params[:lat].to_f, params[:lng].to_f, params[:radius].to_f)
@posts = Post.near(params[:lat].to_f, params[:lon].to_f, params[:radius].to_f)

layar_response = {
:layer => 'hyparlocal',
:hotspots => @posts.collect { |p| post_to_poi(p) },
:errorCode => 0, # OK
:errorString => "OK",
:radius => params[:radius].to_f
}

respond_to do |format|
format.html # near.html.erb
format.json { render json: @posts }
format.layar { render json: layar_response }
end
end
end

+ 14
- 0
app/helpers/posts_helper.rb 查看文件

@@ -1,2 +1,16 @@
module PostsHelper
def post_to_poi(post)
# http://layar.com/documentation/browser/api/getpois-response/
{
:id => post._id,
:anchor => {
:geolocation => {
:lat => post.loc['lat'],
:lon => post.loc['lng'],
:alt => 0
}
},
:title => post.title
}
end
end

+ 2
- 0
config/initializers/mime_types.rb 查看文件

@@ -3,3 +3,5 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

Mime::Type.register_alias "application/json", :layar

Loading…
取消
儲存