Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

GPS Tutorial incomplete - LocationListener not working #186

Closed
w4ldmeister opened this Issue · 6 comments

3 participants

@w4ldmeister

Started yesterday with ruboto.

Tried to get my current location following https://github.com/ruboto/ruboto/wiki/Tutorial%3A-get-current-gps-position

Poorly, location is always null on my Smartphone with Android 2.3.3
Some explanations say, it is because GPS has been off and there is no "lastKnownLocation".
Maybe someone can clarify?

So i tried to register a callback "onLocationChanged" on LocationListener.

The code:

@location_listener = LocationListener.new

@location_listener.on_location_changed do |location|
  Log.v 'TestApp', location.inspect
  toast location.time
end

Fails

E/AndroidRuntime(16040): org.jruby.exceptions.RaiseException: (TypeError) cannot convert instance of class org.jruby.RubyProc to class android.location.Location

I am happy to add more information, as required.
Also i will update the wiki on success.

@donv
Owner
@rscottm
Owner
@rscottm
Owner

There is another option for handling the LocationListener interface. In this case you don't have to generate a class for the interface on your development machine. Instead, just create a Ruby class that implements all of the methods (even if they're empty). The toast method is added to the Activity, so I made a change there.

class MyLocationListener
def onLocationChanged(location)
Log.v 'TestApp', location.inspect
$activity.toast location.time
end

def onProviderDisabled(provider)
end

def onProviderEnabled(provider)
end

def onStatusChanged(provider, status, extras)
end
end

@rscottm
Owner

Ok, I've updated the tutorial. It looks like Android needs a LocationListener to get things rolling.

http://stackoverflow.com/questions/1608632/android-locationmanager-getlastknownlocation-returns-null

I've tested it in Ruboto IRB. Let me know if it works for you.

@donv
Owner

@w4ldmeister Did you get this going?

@rscottm rscottm was assigned
@donv
Owner

Closing since there was no response. @w4ldmeister feel free to open a new issue if you still have problems.

@donv donv closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.