-
Notifications
You must be signed in to change notification settings - Fork 30
Location doesn't work when using GPS or other location providers #65
Comments
http://developer.android.com/reference/android/location/LocationManager.html#getBestProvider(android.location.Criteria, boolean) with http://developer.android.com/reference/android/location/Criteria.html#ACCURACY_COARSE and the GPS permission should fix it, I think ;) |
Would that be smart enough to switch between GPS and cell location if the user turns gps on and off whilst the app is running, or would we need to detect the state change and reinitialise the location listener? |
That, I can't answer. Probably not. :/ |
Not entirely sure if I understood the problem but, regarding location... Anyway, so far, the best advice on location I've seen was here: But maybe I didn't understand the problem hehe :) |
Yeah - put simply it currently just uses the extra-course cell location provider, which fails entirely on devices that don't have cell radios (e.g. Nexus 7). What we really want would be for it to automatically use gps or wifi based location if those are available, but fall back to cell based location if not. It only updates location every half hour, or so, but ideally it'll use as little power as possible. I'll have a look at that example and see if I can rework the existing code to match its suggestions. |
If it isn't for real-time location tracking, what do you think about using the Last Known Location as in the example (under Freshness means never having to wait)? What I mean with this is, the code from that example can be used almost as-is :) I hope this helps (I'm almost getting my watch! YEAH! I could look into this after if you don't mind, I'm really excited! hehe) |
It already does check for the most recent update when it does a weather refresh, in case the OS has a newer location than the one it was last notified about - the main issue is that it won't activate and scan with GPS unless you actively tell it to. Btw, even without a watch you can still experiment with the app - if you tick the "Show fake watches" option in Preferences/Device, then open the Select Watch option, you'll see a "Fake digital watch" entry - select that, and MWM will pretend it's connected to a digital watch - you'll be able to see the location and weather update status on the status tab, and will be able to see what the idle screen(s) look like on the widgets tab, to see what weather data it's pulled in. |
I've used location in some of my Android Apps and I'm sure you can get the On 11 October 2012 12:04, Richard Munn [email protected] wrote:
|
Yeah, we don't even need a particularly accurate fix (we're just trying to get weather for the current town/city, after all) - so really we just need a simple way to get a fairly recent location every time we do a weather refresh, in a manner that will work on devices without cell radios. So ( wifi location || cell location || gps location ) I guess. |
Try using this: LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = manager.getBestProvider(criteria, false);
Location location = manager.getLastKnownLocation(provider); (warning that was from top of my head, needs a bit of testing...) Don't forget to add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> to your manifest ;) (FINE_LOCATION also includes COARSE permission so you only need that one ;) ) |
By the way, can you point me to the place where the Weather update happens? :) |
That stuff all happens within Monitors.java https://github.com/benjymous/MWM-for-Android/blob/master/src/org/metawatch/manager/Monitors.java |
Finally started looking into it! hehe At the moment, anything older than Gingerbread will only use network (which I will change tomorrow or so). Anyway, if you could start having a quick look at the code, anything stupid, just let me know hehe :) (I'm experimenting with fluent pattern which I think fits the purpose but let me know if you don't like the style hehe) |
Yeah, looks good so far. I wouldn't worry too much about adding new functionality for pre-gingerbread, as long as the network location still works - the main issue is location on tablets that don't have a cell radio, of which the vast majority will be running 3.0+ (Only 4% of MW-CE's users are still on 2.1/2.2) So really, we want something like
The current code only updates every half hour, or so - If you're manually polling instead of using the listener, can you wrap that into the existing weather update refresh? |
Ok, great! :) One thing I just noticed... if we have GPS enabled, as we only update every 30 mins... that means it'll go off between updates (unless another app is using it). Either we conclude that we don't need GPS's accuracy for the weather (which I don't think it's the point) or I'll actually start pulling the location using that last best known location and only triggering the update when it isn't good enough (like the article I shared does). What do you think? I'm finishing something else and I'll look into this next :) |
My 2p/2c worth:- The weather doesn't vary much within the location of a single cell tower so I use Wunderground for weather because they are more accurate than the Met
Hope that helps - end 2p/2c :) On 24 October 2012 00:25, Diogo Neves [email protected] wrote:
|
That's a good point! ;) |
Yeah, the weather is (currently) never updated more frequently than every half hour, anyway, so the location doesn't need to be that up to date, though ideally you want to keep it in sync, so that the location will be updated before the weather update, rather than afterwards. |
There should probably be a setting where you can choose to allow GPS usage On 24 October 2012 15:38, Diogo Neves [email protected] wrote:
|
I quite like that suggestion. On 24 October 2012 14:38, Diogo Neves [email protected] wrote:
|
Ok, here's another version, this time with pulling :) It uses whatever is the best available location and requests a single update if it isn't good enough. What do you think? |
I forgot to mention, it's possible to tweak the settings of the location finder, for example, if we do create an option for using GPS or not, the best way to go about it would be to set a new criteria like: Criteria criteria = new Criteria();
if (useGPS)
criteria.setAccuracy(Criteria.ACCURACY_HIGH);
else
criteria.setPowerRequirement(Criteria.POWER_LOW);
locationFinder.setCriteria(criteria); if you set it to low power, it'll still use an accurate location if it is available in the getLastBestKnownLocation() but won't turn the GPS on if it sends the single request. To summarise: |
I'm not entirely sure if I should do this but... |
Ok, submitted another change (the diff link should still work :) ) |
Setting LocationData.received to false will cause all the weather widgets to display a "waiting for location" message, so it's better to just leave the previous known location in place if you're unable to get a new one - weather from the wrong location is better than no weather at all! |
ok, I'll revert to the previous commit which didn't cause that hehe |
Review that one :) doesn't set the received flag |
Should be a simple fix
The text was updated successfully, but these errors were encountered: