Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

GPS Tutorial incomplete - LocationListener not working #186

Closed
w4ldmeister opened this Issue Jun 9, 2012 · 6 comments

Comments

Projects
None yet
3 participants

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.

Owner

donv commented Jun 9, 2012

I'll look at this later today.

Uwe Kubosch
http://ruboto.org/

Owner

rscottm commented Jun 9, 2012

Yes, that tutorial seems incomplete and stale. I'll try to make a pass at
it soon. For now, try

make sure you generated your own listener as shown at the top of the

tutorial

@location_listener = MyLocationListener.new_with_callbacks do
def on_location_changed(location)
Log.v 'TestApp', location.inspect
toast location.time
end
end
On Jun 9, 2012 2:45 AM, "w4ldmeister" <
reply@reply.github.com>
wrote:

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.


Reply to this email directly or view it on GitHub:
#186

Owner

rscottm commented Jun 9, 2012

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

Owner

rscottm commented Jun 11, 2012

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.

Owner

donv commented Sep 2, 2012

@w4ldmeister Did you get this going?

@ghost ghost assigned rscottm Dec 1, 2012

Owner

donv commented Dec 1, 2012

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

@donv donv closed this Dec 1, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment