Skip to content

Instantly share code, notes, and snippets.

@thomasv314
Created July 14, 2011 15:19
Show Gist options
  • Save thomasv314/1082653 to your computer and use it in GitHub Desktop.
Save thomasv314/1082653 to your computer and use it in GitHub Desktop.
Layar#new_pois is making a request for listings in near a certain lat/long/radius. It pulls all those listings and iterates through to grab data about each. GeoKit gem is returning the sam lat/long/distance for each. Ideas?
class LayarController < ApplicationController
include LayarHelper
def new_pois
userId = params[:userId]
developerId = params[:developerId]
developerHash = params[:developerHash]
timestamp = params[:timestamp]
layerName = params[:layerName]
lat = params[:lat].to_f
lng = params[:lon].to_f
radius = (params[:radius] || "2500").to_f / 1000.0
begin
points = Listing.within(params[:radius], :origin => [lat, lng])
current = Geokit::LatLng.new(lat, lng)
#create hotspots array to store point data in
hotspots = []
points.each do |point|
hotspots << point.get_point(current)
end
result = {:nextPageKey => "#{lat},#{lng}", :morePages => false, :layer => layerName,
:errorCode => 0, :errorString => "ok", :hotspots => hotspots}
render :text => result.to_json
rescue StandardError => e
result = {:nextPageKey => "#{lat},#{lng}", :morePages => false, :layer => layerName,
:errorCode => 1, :errorString => "Unexpected Error: #{e.message}", :hotspots => []}
render :text => result.to_json
end
end
end
class Listing < ActiveRecord::Base
set_table_name :Listing
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:lat_column_name => :latitude,
:lng_column_name => :longitude
def get_point(latlong)
{
:actions => [],
:distance => self.distance_to(latlong) * 1000,
:attribution => self.title,
:id => "point_#{self.id}",
:imageURL => nil,
:lat => (self.latitude * 1000000).to_i,
:lon => (self.longitude * 1000000).to_i,
:title => self.title,
:line2 => "Thiis is line two.",
:line3 => "This is line three.",
:line4 => "Guess what line this is.",
:type => 0
}
end
end
{
"nextPageKey": "39.905258,-74.975031",
"morePages": false,
"layer": null,
"errorCode": 0,
"errorString": "ok",
"hotspots": [
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "DiVello's Deli Kresson Rd Haddonfield NJ 08034",
"id": "point_25",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "DiVello's Deli Kresson Rd Haddonfield NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Normas Mediterranean Restaurant Rt 70 Cherry Hill NJ",
"id": "point_56",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Normas Mediterranean Restaurant Rt 70 Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Steak and Ale Restaurant near Rt 70 Cherry Hill NJ is Now Closed!",
"id": "point_69",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Steak and Ale Restaurant near Rt 70 Cherry Hill NJ is Now Closed!",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Cherry Hill Pizza - NJ ",
"id": "point_85",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Cherry Hill Pizza - NJ ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Aloe Fusion Restaurant Menu Berlin Rd Cherry Hill NJ",
"id": "point_102",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Aloe Fusion Restaurant Menu Berlin Rd Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Dunkin Donuts Coffee Locations Rt 70 East Cherry Hill NJ",
"id": "point_455",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Dunkin Donuts Coffee Locations Rt 70 East Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Burger King Restaurant Menu Rt 70 Cherry Hill New Jersey",
"id": "point_458",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Burger King Restaurant Menu Rt 70 Cherry Hill New Jersey",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Andreotti's Viennese Cafe Restaurant Menu Rt 70 Cherry Hill Nj",
"id": "point_460",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Andreotti's Viennese Cafe Restaurant Menu Rt 70 Cherry Hill Nj",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "3 Brothers Pizza Cherry Hill - Rt 70 near Springdale Rd Cherry Hill 08034 - Pizza Delivery",
"id": "point_473",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "3 Brothers Pizza Cherry Hill - Rt 70 near Springdale Rd Cherry Hill 08034 - Pizza Delivery",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Qdoba Mexican Grill Restaurant Menu Cherry Hill: Rt 70 & Kings Highway Cherry Hill NJ 08034",
"id": "point_497",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Qdoba Mexican Grill Restaurant Menu Cherry Hill: Rt 70 & Kings Highway Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Five 5 Guys Burgers and Fries Menu Restaurant Ellisburg Shopping Center Cherry Hill, NJ 08034",
"id": "point_504",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Five 5 Guys Burgers and Fries Menu Restaurant Ellisburg Shopping Center Cherry Hill, NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Christopher Steakhouse & Seafood Restaurant Menu Kresson Rd Cherry Hill NJ 08034",
"id": "point_764",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Christopher Steakhouse & Seafood Restaurant Menu Kresson Rd Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Kaminski's Bar and Grill Restaurant Menu Brace Road Cherry Hill NJ 08034",
"id": "point_765",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Kaminski's Bar and Grill Restaurant Menu Brace Road Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Cheesecake Factory Restaurant Menu - Cherry Hill Garden State Racetrack Rt 70 Cherry Hill NJ 08034",
"id": "point_780",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Cheesecake Factory Restaurant Menu - Cherry Hill Garden State Racetrack Rt 70 Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Andreottis Viennese Cafe Restaurant Menu and Pastry Shop 1442 Rt 70 Cherry Hill NJ 08034",
"id": "point_784",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Andreottis Viennese Cafe Restaurant Menu and Pastry Shop 1442 Rt 70 Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Pho Barclay Noodle House Thai Restaurant Menu 1409 Rt. 70 East Cherry Hill NJ 08034",
"id": "point_806",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Pho Barclay Noodle House Thai Restaurant Menu 1409 Rt. 70 East Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": " Cous Cous Moroccan Cuisine Hookah Lounge Restaurant Menu BYOB Barclay Plaza Cherry Hill NJ",
"id": "point_807",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": " Cous Cous Moroccan Cuisine Hookah Lounge Restaurant Menu BYOB Barclay Plaza Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Normas Mediterranean Middle Eastern Restaurant Menu BYOB Barclay Plaza Rt 70 Cherry Hill NJ ",
"id": "point_808",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Normas Mediterranean Middle Eastern Restaurant Menu BYOB Barclay Plaza Rt 70 Cherry Hill NJ ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Mirabella Cafe Restaurant Menu - Rt 70 Barclay Plaza Shopping Center Cherry Hill NJ 08034",
"id": "point_809",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Mirabella Cafe Restaurant Menu - Rt 70 Barclay Plaza Shopping Center Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Tutti Toscani by Aldo Lamberti Restaurant Menu 1491 Brace Road Cherry Hill, NJ 08034",
"id": "point_834",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Tutti Toscani by Aldo Lamberti Restaurant Menu 1491 Brace Road Cherry Hill, NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Johnnys Pizza 717 Kings Highway North Cherry Hill, NJ Steaks Hoagies eat in take out restaurant",
"id": "point_872",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Johnnys Pizza 717 Kings Highway North Cherry Hill, NJ Steaks Hoagies eat in take out restaurant",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Cheesecake Factory Cherry Hill Restaurant Listing, Reviews Garden State Racetrk Rt 70 Cherry Hill NJ",
"id": "point_902",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Cheesecake Factory Cherry Hill Restaurant Listing, Reviews Garden State Racetrk Rt 70 Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Johnnys Pizza 717 Kings Highway North Cherry Hill, NJ Steaks Hoagies eat in take out restaurant",
"id": "point_921",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Johnnys Pizza 717 Kings Highway North Cherry Hill, NJ Steaks Hoagies eat in take out restaurant",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Tutti Toscani by Aldo Lamberti Restaurant Reviews 1491 Brace Road Cherry Hill, NJ 08034",
"id": "point_1021",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Tutti Toscani by Aldo Lamberti Restaurant Reviews 1491 Brace Road Cherry Hill, NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "Christopher - 306 Kresson Road Cherry Hill NJ 08034",
"id": "point_1077",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "Christopher - 306 Kresson Road Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1543.853922196348,
"attribution": "P.J. Whelihan’s Pub & Restaurant Menu - 1854 E Marlton Pike Cherry Hill NJ 08034",
"id": "point_1084",
"imageURL": null,
"lat": 39907309,
"lon": -75004004,
"title": "P.J. Whelihan’s Pub & Restaurant Menu - 1854 E Marlton Pike Cherry Hill NJ 08034",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Sakura Spring Restaurant Menu: Japanese Chinese Sushi Rt 70 Cherry Hill NJ 08003 ",
"id": "point_505",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Sakura Spring Restaurant Menu: Japanese Chinese Sushi Rt 70 Cherry Hill NJ 08003 ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Red Lantern Restaurant Menu Chinese & Japanese: Evesham Rd Cherry Hill NJ 08003 near Short Hill Ctr",
"id": "point_508",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Red Lantern Restaurant Menu Chinese & Japanese: Evesham Rd Cherry Hill NJ 08003 near Short Hill Ctr",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Swanky Bubbles Champagne Bar Restaurant Menu: Evesham Rd Cherry Hill 08003 near Voorhees",
"id": "point_509",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Swanky Bubbles Champagne Bar Restaurant Menu: Evesham Rd Cherry Hill 08003 near Voorhees",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Bobby Chez Crabcakes Cherry Hill Restaurant Location Menu, Hours RT 70 Marlton Pike, Cherry Hill, NJ",
"id": "point_1032",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Bobby Chez Crabcakes Cherry Hill Restaurant Location Menu, Hours RT 70 Marlton Pike, Cherry Hill, NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Big Johns Pizza & Cheesesteak Restaurant Menu & Coupons 1800 Marlton Pike East Cherry Hill NJ",
"id": "point_1039",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Big Johns Pizza & Cheesesteak Restaurant Menu & Coupons 1800 Marlton Pike East Cherry Hill NJ",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "The Cool Dog Cafe - Gourmet Hot Dogs and Sliders - 2091 Route 70E Cherry Hill, NJ 08003",
"id": "point_1058",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "The Cool Dog Cafe - Gourmet Hot Dogs and Sliders - 2091 Route 70E Cherry Hill, NJ 08003",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "The Kibitz Room Delicatessen, Catering & Bakery 100 Springdale Rd. Cherry Hill, NJ 08003",
"id": "point_1060",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "The Kibitz Room Delicatessen, Catering & Bakery 100 Springdale Rd. Cherry Hill, NJ 08003",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Romanza Italian Restaurant - 1900 Springdale Rd Cherry Hill NJ 08003",
"id": "point_1078",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Romanza Italian Restaurant - 1900 Springdale Rd Cherry Hill NJ 08003",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
},
{
"actions": [],
"distance": 1174.6985238097927,
"attribution": "Big John's Cheese Steaks - 1800 Rt 70 E Cherry Hill NJ 08003",
"id": "point_1079",
"imageURL": null,
"lat": 39888300,
"lon": -74973840,
"title": "Big John's Cheese Steaks - 1800 Rt 70 E Cherry Hill NJ 08003",
"line2": "Thiis is line two.",
"line3": "This is line three.",
"line4": "Guess what line this is.",
"type": 0
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment