Don't like ads? PRO users don't see any ads ;-)
Guest

Rhomobile Geo Controller

By: a guest on Apr 24th, 2012  |  syntax: Ruby  |  size: 1.23 KB  |  hits: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'rho/rhocontroller'
  2. require 'helpers/browser_helper'
  3.  
  4. class GeoController < Rho::RhoController
  5.   include BrowserHelper
  6.  
  7.   def geo_callback
  8.     if @params['known_position'].to_i != 0 && @params['status'] == 'ok'
  9.         $latitude = @params['latitude']
  10.         $longitude = @params['longitude']
  11.       end
  12.     end
  13.  
  14.     # show error if timeout expired and GPS receiver didn't acquire position
  15.     if @params['available'].to_i == 0 || @params['status'] != 'ok'
  16.       @@gps_tries += 1
  17.       if @@gps_tries > 10
  18.         Alert.show_popup(
  19.         :message=>"Unable to obtain a GPS Signal.
  20.          Please make sure your GPS is activated. For iPhone, go to Settings ->
  21.          Location Services and makes sure it is 'On'. For Android, go to
  22.          Applications -> Settings -> Location & Security. Make sure that 'Use
  23.          GPS Satellites' is checked.",
  24.         :title=>"GPS Error",
  25.         :buttons => ["Ok"]
  26.         )
  27.       end
  28.     end
  29.   end
  30.  
  31.   def get_my_location
  32.     if GeoLocation.known_position?
  33.       $latitude = GeoLocation.latitude
  34.       $longitude = GeoLocation.longitude
  35.     else
  36.       GeoLocation.set_notification( url_for(:controller => :Geo, :action => :geocall_back), "","")
  37.     end
  38.   end
  39. end