Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Created March 26, 2012 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ornerymoose/2202702 to your computer and use it in GitHub Desktop.
Save ornerymoose/2202702 to your computer and use it in GitHub Desktop.
Gmaps4rails gem-Issue with map not being displayed, minimum distance is being calculated fine
def show
@textbook = Textbook.find(params[:id])
@this_user = User.find_by_id(session[:user_id])
@textbook.user_textbook_statuses.each do |attribute|
@map = Map.new(:to_location_id => attribute.user.location_id, from_location_id:
@this_user.location_id)
@from_address = @map.from_location.as_json(:only => [:latitude, :longitude])
@to_address = @map.to_location.as_json(:only => [:latitude, :longitude])
@distance = Haversine.distance(@from_address["latitude"], @from_address["longitude"],
@to_address["latitude"], @to_address["longitude"]).to_ft
@map.update_attributes(:distance => @distance)
@map.save
locations = [ @from_address, @to_address ]
locations = locations.map do |marker|
{ lng: marker['longitude'], :lat => marker['latitude'] }
end
map = [ locations ]
@location = map.to_json
end
@textbook_isbn = @textbook.isbn
@results = JSON.parse(open("http://api2.campusbooks.com/12/rest/bookprices?
key=4YMl9bgQwpcb7JzZBsr&isbn=#{@textbook_isbn}&format=json").read)
@title = @results["response"]["page"]["book"]["title"]
@each_offer = @results["response"]["page"]["offers"]["condition"].first["offer"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment