7 Replies Latest reply on May 20, 2015 10:16 AM by Jon Tara

    I am having an issue with the geolocation lat long data

    Subhajit Choudhury

      Hi,

       

      I have been through numerous searched results and rhomobile docs but could not get the geolocation working.

      Following tutorials and explanations from various posts I have done the following but to no help ---

      1) enabled capabilities to gps

      2) added necessary code for the geolocation to work

      Below is the response returned

      APP| RHO serve: /app/GeoTest/geo_callback

      Params: {"rho_callback"=>"1", "status"=>"error", "error_code"=>"12", "available"=>"0", "known_position"=>"0", "latitude"=>"0.0", "longitude"=>"0.0", "accuracy"=>"0.0"}

      No matter what I do, everytime it is 0

       

      below is my controller code

      require 'rho/rhocontroller'

      require 'helpers/browser_helper'

       

       

      class GeoTestController < Rho::RhoController

        include BrowserHelper

       

       

        def index

        if !GeoLocation.known_position?

        GeoLocation.set_notification(url_for(:action => :geo_callback), "", 2)

       

        #redirect user to waiting/loading screen

        else

        redirect url_for(:action => :show)

        end

        end

       

        def geo_callback

        if @params['known_position'].to_i != 0 && @params['status'] == 'ok'

        #turn off the Geolocation callback sync

        GeoLocation.turnoff

        puts "Location Found"

        #forward to the page

        WebView.navigate url_for(:action => :show)

        else

          puts "Disaster"

          WebView.navigate url_for(:action => :show)

        end

        end

       

        def show

          render :action=> :show

        end

      end

       

      What exactly needs to be done to get it working. Has it got something to do with RhoElements. Do I need to get the licensing?

      Help would be very much appreciated

      Thanks

        • Re: I am having an issue with the geolocation lat long data
          Robert Galvin

          What device and version of OS/Rho are you using?

            • Re: I am having an issue with the geolocation lat long data
              Subhajit Choudhury

              Hi Rob,

              Appreciate for helping me out

              I am actually trying to run the code in RHOSimulator. Target device would be Android 4.4 and above.

              Version of Rho 4.1

               

              Wanted to update you, I was late in replying back coz I was totally involved in solving it out and much to my amusement, it is working in real android device running 5.0 android. But the callback looks like not working and the location changes by say .00xxxx when i travelled fo atleast say 5-6 KMS.

              Could you please help me out on that?

            • Re: I am having an issue with the geolocation lat long data
              Jon Tara

              Real device, simulator, or RhoSimulator?

                • Re: I am having an issue with the geolocation lat long data
                  Subhajit Choudhury

                  Hi, Jon

                  Thanks for helping me out

                   

                  As I replied to Rob, it is working on the real device running 5.0 android, but not on simulator. Is there any hack?

                   

                  Moreover, the callback looks like not working and the location changes by say .00xxxx when i travelled fo atleast say 5-6 KMS.

                  Could you please help me out on that?

                    • Re: I am having an issue with the geolocation lat long data
                      Robert Galvin

                      Geolocation and other 'hardware' related APIs will not work in the simulator.

                      • Re: I am having an issue with the geolocation lat long data
                        Jon Tara

                        As Rob mentioned, RhoSimulator doesn't support GeoLocation.

                         

                        In general, I don't find that RhoSimulator provides a very realistic environment. The most important thing that I think that RhoSimulator offers is the ability to easily debug your Ruby code, since you can set breakpoints and examine variables. But I don't find that it accurately reflects the appearance you will see on a real device, and of course no support for hardware features.

                         

                        But you can use the official Google Android simulator. But the Android simulator is very slow - even if you use the X86 version (ARM emulator is simply ridiculously slow) and even if you use Intel HAXM (Hardware Accelerated eXecution manger).

                         

                        I've been using the GenyMotion Android simulator, which is a third-party alternative for Android. It is every bit as fast and responsive as the official Apple simulator is for iOS development, and does support most hardware options, including GeoLocation. It is a commercial product, and isn't cheap, but if you are an Indie developer, there is a special $99/year option. It can pretty accurately emulate many popular real devices (there is a library of Android devices). It runs X86 code only (there used to be an ARM emulator option.). I just build my Rhodes project to make a binary for both ARM and X86 (which you probably should do anyway, because there are increasingly more X86 Android tablets). Install is by simply dragging the .apk file to the simulated device window. And then I can install the very same binary on a real device using adb. GenyMotion  runs on top of (free) Oracle VirtualBox.

                         

                        Building Android projects is I'm afraid very, very slow, but RhoMobile has done a great job of improving the build system lately, and the common parts of Rhodes are built once for your project and saved in your project, so when you update, it can only take a minute or maybe less on a fast host. (A full build, though can take 15 minutes or more!) (If you are creating a native extension - as I am - , there is a bit of a glitch with the build system that means in some circumstances you may have to do a full rebuild, but for most projects this is not needed.)

                         

                        With RhoSimulator, you can just change your Ruby code without having to rebuild, and so it is a great convenience. But not usable when testing hardware features.

                         

                        Keep in mind that you can still inspect/debug CSS and Javascript by using Chrome desktop browser remote debug tools when you use a hardware device or non-Rho simulator. (If you are testing with a recent enough version of Android).

                        • Re: I am having an issue with the geolocation lat long data
                          Jon Tara

                          I'm afraid I'm not very familiar with specifics of Android GeoLocation implementation. (I am for iOS.)

                           

                          Can you tell us what version of Rhodes you are using? It might matter.

                           

                          Rhodes has flipped-flopped back and forth (depending on version) for iOS at least (but I don't know about Android) as to whether you get callbacks continuously until you disable them, or you need to re-enable the callback after you receive each one.