[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
So I got it working now. I'm using the service thread to get the location. And that's the way I did it: http://paste.pocoo.org/show/b67L69qf5QDNtq1pTzZz/ It works pretty fine. But you should add some timeout to the condition.await() of the background thread. Regards! On 21 Aug., 16:45, code_android_festival_way [EMAIL PROTECTED] wrote: The LocationManager.request*Updates methods must be called from a Looper thread, such as the main thread of an Activity. Additional method variants have been added that take an explicit Looper argument to allow for use outside of a main thread. This could be the solution for my problem. Now I have to understand what that means for me. If someone knows the solution I'm looking forward reading it. :-) Regards! On 21 Aug., 15:50, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your response. I will try handling this in a different way now. If I'm struggling I will come back to your offer. :-) Regards! On 21 Aug., 15:38, Mark Murphy [EMAIL PROTECTED] wrote: code_android_festival_way wrote: In M5 I only called getCurrentLocation() and everything was fine. Now as the methode is gone I need to set this update request to the LocationManager in order to get a not outdatet position. To achieve that I have to loop inside my geo location class and wait for the Listener to be invoked in order to be able to return some location from the geo location class. Off the cuff, I suspect you will need to have whatever code uses GeoProvider switch to supporting asynchronous delivery of location data. It may no longer be possible to synchronously get your current position. But, I won't be diving into the new mapping code until this weekend at the earliest, so I can't comment on how better to handle your situation until then. If you're still struggling come Monday, send me an email to remind me to post something. -- Mark Murphy (a Commons Guy)http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Ok. It was a silly question. Looper.prepare(); added. But I dont get any LocationUpdates. I have pushed locations to the device through the DDMS interface but get no LocationUpdate. On 21 Aug., 11:40, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
I've added Location loc = new Location(lP.getName()); loc.setLatitude(37.422006); loc.setLongitude(-122.084095); lM.setTestProviderLocation(lP.getName(), loc); but the LocationListener doesnt get called. So I get no location update. On 21 Aug., 11:46, code_android_festival_way [EMAIL PROTECTED] wrote: Ok. It was a silly question. Looper.prepare(); added. But I dont get any LocationUpdates. I have pushed locations to the device through the DDMS interface but get no LocationUpdate. On 21 Aug., 11:40, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
I'm not at a PC I can test with, but try switching the order of your setTestProviderEnabled and setTestProviderStatus commands. I know in my code I've done it the other way around :) On 21 Aug, 11:10, code_android_festival_way [EMAIL PROTECTED] wrote: I've added Location loc = new Location(lP.getName()); loc.setLatitude(37.422006); loc.setLongitude(-122.084095); lM.setTestProviderLocation(lP.getName(), loc); but the LocationListener doesnt get called. So I get no location update. On 21 Aug., 11:46, code_android_festival_way [EMAIL PROTECTED] wrote: Ok. It was a silly question. Looper.prepare(); added. But I dont get any LocationUpdates. I have pushed locations to the device through the DDMS interface but get no LocationUpdate. On 21 Aug., 11:40, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding!- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Getting the status bar icon is a good sign -- that means the GPS_PROVIDER is receiving the updates. I've got one more cheap/easy idea for you. I'm not sure if 0 is a valid limit to set for the refresh time / distance. Try setting it to 1000 (milliseconds) and 1 (meter) to see if that helps. On 21 Aug, 12:41, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I've changed the order the other way round but get the same result. Waiting for the Listener to be invoked but nothing happens. I tried it with the DDMS again and get an icon in the status bar (http:// img.skitch.com/20080821-eypgin7w8fd9ku3ftj1ix38s7.jpg) after pushing a single location. But the Listener doesnt get invoked either. So I'm pretty much at the end of my knowledge to what I can try in order to get my geo location. :-) Regards! On 21 Aug., 12:29, Reto [EMAIL PROTECTED] wrote: I'm not at a PC I can test with, but try switching the order of your setTestProviderEnabled and setTestProviderStatus commands. I know in my code I've done it the other way around :) On 21 Aug, 11:10, code_android_festival_way [EMAIL PROTECTED] wrote: I've added Location loc = new Location(lP.getName()); loc.setLatitude(37.422006); loc.setLongitude(-122.084095); lM.setTestProviderLocation(lP.getName(), loc); but the LocationListener doesnt get called. So I get no location update. On 21 Aug., 11:46, code_android_festival_way [EMAIL PROTECTED] wrote: Ok. It was a silly question. Looper.prepare(); added. But I dont get any LocationUpdates. I have pushed locations to the device through the DDMS interface but get no LocationUpdate. On 21 Aug., 11:40, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding!- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Well I've chosen the 0 because the sample appliction provided by google uses the same parameter value. Could it be that my while loop blocks the class (thread) and so the listenere cant be invoked? On 21 Aug., 13:57, Reto [EMAIL PROTECTED] wrote: Getting the status bar icon is a good sign -- that means the GPS_PROVIDER is receiving the updates. I've got one more cheap/easy idea for you. I'm not sure if 0 is a valid limit to set for the refresh time / distance. Try setting it to 1000 (milliseconds) and 1 (meter) to see if that helps. On 21 Aug, 12:41, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I've changed the order the other way round but get the same result. Waiting for the Listener to be invoked but nothing happens. I tried it with the DDMS again and get an icon in the status bar (http:// img.skitch.com/20080821-eypgin7w8fd9ku3ftj1ix38s7.jpg) after pushing a single location. But the Listener doesnt get invoked either. So I'm pretty much at the end of my knowledge to what I can try in order to get my geo location. :-) Regards! On 21 Aug., 12:29, Reto [EMAIL PROTECTED] wrote: I'm not at a PC I can test with, but try switching the order of your setTestProviderEnabled and setTestProviderStatus commands. I know in my code I've done it the other way around :) On 21 Aug, 11:10, code_android_festival_way [EMAIL PROTECTED] wrote: I've added Location loc = new Location(lP.getName()); loc.setLatitude(37.422006); loc.setLongitude(-122.084095); lM.setTestProviderLocation(lP.getName(), loc); but the LocationListener doesnt get called. So I get no location update. On 21 Aug., 11:46, code_android_festival_way [EMAIL PROTECTED] wrote: Ok. It was a silly question. Looper.prepare(); added. But I dont get any LocationUpdates. I have pushed locations to the device through the DDMS interface but get no LocationUpdate. On 21 Aug., 11:40, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
code_android_festival_way wrote: Could it be that my while loop blocks the class (thread) and so the listenere cant be invoked? Sorry, I haven't looked at your code. But you may be right on this. Android applications have the main event thread, plus any secondary threads you create on your own. Listener callbacks, AFAIK, happen on the main event thread, which is why you can update UI elements without muss or fuss. If your while loop is also on the main event thread, you never release that thread, and hence your listeners may never be called. -- Mark Murphy (a Commons Guy) http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
hello dears, sorry for this interrupted question but i'm tring to download the SDK 0.9 but the following error appears: The requested URL /android/android-sdk-windows-0.9_beta.zip was not found on this server. any help ! On 8/21/08, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your reponse. I'm trying to implement the requestUpdates() now. At the moment I'm faced with the follwing problem. I've implemented the LocationListener but always get the following LogCat error. Can't create handler inside thread that has not called Looper.prepare() Well I'm calling my geo class in a thread that was started by a service. At the moment it looks like this. What do I have to change in order to get the listener working? My Geo class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ Regards! On 20 Aug., 18:36, Reto [EMAIL PROTECTED] wrote: The getLastKnownLocation method will return null until the provider you specify has gotten at least one update. In practice that means you need to have an application (any application, doesn't have to be the one your testing) request (and receive) updates at least once in your emulator session before it will getLastKnown will return a value. You can disable the updates after the first return if you want to, in fact that's probably a reasonable way of implementing the 'getCurrentLocation' functionality you're after. Cheers Reto On 20 Aug, 14:21, code_android_festival_way [EMAIL PROTECTED] wrote: Firstly I got the question why I can't get the currentlocationany more. I don't need repeating updates of my position I just need the currentlocation. At the moment I'm using getLastKnownLocation() but I would assume that this position could be very outdated. Furthermore the method getLastKnownLocation() returns me aLocation object that is null. Here is the code that I'm using at the moment: LocationManager lM = (LocationManager)context.getSystemService(context.LOCATION_SERVICE); LocationProvider lP = lM.getProvider(gps); Locationloc = lM.getLastKnownLocation(lP.getName()); String[]location= {String.valueOf(loc.getLongitude()),String.valueOf(loc.getLatitude())}; I've added the following permission to my manifest file: uses-permission android:name=android.permission.ACCESS_LOCATION / uses-permission android:name=android.permission.ACCESS_FINE_LOCATION / uses-permission android:name=android.permission.ACCESS_GPS / uses-permission android:name=android.permission.ACCESS_MOCK_LOCATION / But I'm always getting a Nullpointer Exception using theLocation. (so theLocationreturned is null) Could you give me a hint how I could achieve to get my current/ lastKnownlocationin 0.9? (in M5 everything was fine) Looking forward getting your answers. Regards and happy coding! -- Regards Mazen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
I agree. There's definitely a very good chance that the while loop is blocking the listener callback. Note: I believe he's running the whole lot in a new thread (and forcing the update requests to fire on that same thread) rather than the main event thread, but it still turns in to the same problem in the end. On 21 Aug, 13:47, Mark Murphy [EMAIL PROTECTED] wrote: code_android_festival_way wrote: Could it be that my while loop blocks the class (thread) and so the listenere cant be invoked? Sorry, I haven't looked at your code. But you may be right on this. Android applications have the main event thread, plus any secondary threads you create on your own. Listener callbacks, AFAIK, happen on the main event thread, which is why you can update UI elements without muss or fuss. If your while loop is also on the main event thread, you never release that thread, and hence your listeners may never be called. -- Mark Murphy (a Commons Guy)http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Well I'm starting a service from my main thread. (some activity) In the service I'm starting a new thread and do some work. (communication with external APIs (flickr)) While that work I need the position of the device. To get the position I had written this class: http://paste.pocoo.org/show/80ypWR00yHnHRz9pN7mc/ In M5 I only called getCurrentLocation() and everything was fine. Now as the methode is gone I need to set this update request to the LocationManager in order to get a not outdatet position. To achieve that I have to loop inside my geo location class and wait for the Listener to be invoked in order to be able to return some location from the geo location class. Now I don't really know how to do that the right way. (not blocking the thread) I would appreciate every hint that you could give me. I dont really know how to handle that situation. Best Regards! On 21 Aug., 14:47, Mark Murphy [EMAIL PROTECTED] wrote: code_android_festival_way wrote: Could it be that my while loop blocks the class (thread) and so the listenere cant be invoked? Sorry, I haven't looked at your code. But you may be right on this. Android applications have the main event thread, plus any secondary threads you create on your own. Listener callbacks, AFAIK, happen on the main event thread, which is why you can update UI elements without muss or fuss. If your while loop is also on the main event thread, you never release that thread, and hence your listeners may never be called. -- Mark Murphy (a Commons Guy)http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
code_android_festival_way wrote: In M5 I only called getCurrentLocation() and everything was fine. Now as the methode is gone I need to set this update request to the LocationManager in order to get a not outdatet position. To achieve that I have to loop inside my geo location class and wait for the Listener to be invoked in order to be able to return some location from the geo location class. Off the cuff, I suspect you will need to have whatever code uses GeoProvider switch to supporting asynchronous delivery of location data. It may no longer be possible to synchronously get your current position. But, I won't be diving into the new mapping code until this weekend at the earliest, so I can't comment on how better to handle your situation until then. If you're still struggling come Monday, send me an email to remind me to post something. -- Mark Murphy (a Commons Guy) http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
Thank you for your response. I will try handling this in a different way now. If I'm struggling I will come back to your offer. :-) Regards! On 21 Aug., 15:38, Mark Murphy [EMAIL PROTECTED] wrote: code_android_festival_way wrote: In M5 I only called getCurrentLocation() and everything was fine. Now as the methode is gone I need to set this update request to the LocationManager in order to get a not outdatet position. To achieve that I have to loop inside my geo location class and wait for the Listener to be invoked in order to be able to return some location from the geo location class. Off the cuff, I suspect you will need to have whatever code uses GeoProvider switch to supporting asynchronous delivery of location data. It may no longer be possible to synchronously get your current position. But, I won't be diving into the new mapping code until this weekend at the earliest, so I can't comment on how better to handle your situation until then. If you're still struggling come Monday, send me an email to remind me to post something. -- Mark Murphy (a Commons Guy)http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: LocationManager - getLastKnownLocation() - NullPointer Exception
The LocationManager.request*Updates methods must be called from a Looper thread, such as the main thread of an Activity. Additional method variants have been added that take an explicit Looper argument to allow for use outside of a main thread. This could be the solution for my problem. Now I have to understand what that means for me. If someone knows the solution I'm looking forward reading it. :-) Regards! On 21 Aug., 15:50, code_android_festival_way [EMAIL PROTECTED] wrote: Thank you for your response. I will try handling this in a different way now. If I'm struggling I will come back to your offer. :-) Regards! On 21 Aug., 15:38, Mark Murphy [EMAIL PROTECTED] wrote: code_android_festival_way wrote: In M5 I only called getCurrentLocation() and everything was fine. Now as the methode is gone I need to set this update request to the LocationManager in order to get a not outdatet position. To achieve that I have to loop inside my geo location class and wait for the Listener to be invoked in order to be able to return some location from the geo location class. Off the cuff, I suspect you will need to have whatever code uses GeoProvider switch to supporting asynchronous delivery of location data. It may no longer be possible to synchronously get your current position. But, I won't be diving into the new mapping code until this weekend at the earliest, so I can't comment on how better to handle your situation until then. If you're still struggling come Monday, send me an email to remind me to post something. -- Mark Murphy (a Commons Guy)http://commonsware.com Warescription: All titles, revisions, ebook formats, just $35/year --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] Announcing the new Android 0.9 SDK beta! http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---