Browse Source

Added start of custom response for Layar

master
Adrian Short 12 years ago
parent
commit
360587a1ad
3 changed files with 28 additions and 1 deletions
  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 View File

@@ -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 View File

@@ -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 View File

@@ -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…
Cancel
Save