Can we use Coarse location only? (No need to wait for GPS satellites)

Hello,

I have imagined an app that will need to determine the user’s approximate location. It doesn’t have to be precise, I just need coordinates good enough to determine the city the user is in (or close to).

The app is mostly going to be used in-doors, so asking the GPS sensor for satellite location data is useless.

And obviously the app can’t ask the user to “go outside and wait for location” :smiley:

The app will also need to get the location (and store it) in a very short timeframe, ideally 5-10 seconds after starting the app.

Coarse network/wifi location is pretty fast, so it should work just fine.

Now to my question :

Can I somehow force my Corona app to only use coarse location and give me the approximate location data as soon as it can?

I have tried playing with the GPS Sample app, but that only shows your coordinates if GPS (fine) location is enabled on the device, and you get a GPS satellite Lock.

The GPS sample app will not give me any coordinates if:

  • I am inside and can’t get GPS satellite lock
  • I disable the GPS location in device settings (even though the coarse - wifi/cellular location is enabled)

Can anyone please help me, is this even possible?

Thank you for any ideas.

Best

Joe

I don’t believe this is possible with Corona SDK.  It would be possible with Corona Enterprise where you could reach into the native SDK’s to do things.

Rob

Idea: how about writing a webservice (php probably) that you send a request to, it returns the location based on the ip address, and you use that data to work with

That’s not always that reliable.  Wireless vendors are notorious for reporting the wrong location.  WiFi hot spots are also likely to report the wrong place as well if you base it on IP address.  There is one spot here in Raleigh, NC that I get a California location based on the IP address, but then it’s better than nothing.

Rob

Yeah, I have gone through 3 isp providers here and the closest one got was a city an hours drive away, and thr furthest one got was a 4 hour drive away :slight_smile:

So i agree, it would have mixed reliability

ok, well thanks everyone for responding.

as for the ip geolocation, i thought about that, and as said before me, the location of a cellular data ip is usually way off - for example my cellphone data provider sometimes even locates me to London, while i’m in a totally different country… so that’s a no go.

i am quite saad there is no way to use the coarse data? as far as i understood from reading how corona works, it is supposedly first getting coarse data to get an approximate location, which it then uses to speed up the fine gps location fix… is there really no way to acess at least some preliminary location data before the gps fix? all i’d need is a city name…

if not, that pretty much kills my main app idea, at least with corona for now :frowning:

thanks

I am still looking for other options.

I was just trying native.newMapView , thinking maybe the maps use the system’s libraries and can retrieve the coarse location earlier then when GPS is locked…

but so far no luck.

also, I noticed in the documentation a method on SYSTEM library :

system.setLocationAccuracy(0)

Could this help? Can’t test it now, but aside from the documentation I haven’t found anyone really using this, and it almost seems like it’s iOS focused, no mention of Android anywhere… maybe if we set the LocationAccuracy to a high number, it may provide me with location coordinates as soon as it gets any, even from the coarse sensors?

ideas?

On Android, Corona supports retrieving the device’s location from both the GPS and WiFi/CelluarService (aka: Coarse Location).  Which location service Corona will use depends on the Android permission you give your app.  This is documented here…

   http://docs.coronalabs.com/api/event/location/index.html#android

We also demonstrate this in sample app “Hardware/GPS”, which is included with the Corona Simulator.  The “build.settings” file shows both permissions applied, explaining what each of them do.

The ideal approach is to set up your app to use both Android location permissions.  Odds are Corona will fetch the device’s coarse location first, which usually comes in within the first few seconds.  How long it takes Android to get a lock on a GPS satellite tends to seriously vary between devices… sometimes taking a few minutes.  Or you may not get a lock at all if you’re indoors, as you have noted.  If you’re worried about inaccuracy of the received coarse location, then you can remove that Android permission from your app, which means you have to wait longer for a GPS lock… and as you have noted, you might not get a lock at all while indoors.  There’s really nothing more you can do about this.  But you would hope that a phone would favor the location retrieved from the celluar service than WiFi, but of course that’s not an option on most tablets.

well as i stated, i have no problem with innacuracy, as i only need to know the city of the user, so even a 5 mile radius would usually do…

unfortunately, i have tested the Hardware/GPS sample app, and from my test on android devices (HTC Desire S, Samsung S4 Mini, ASUS TF101), neither one gives ANY location data, until I go outside and a true GPS lock is acquired.

so in essence, it’s completely ignoring the COARSE data, and waiting until the FINE data is available.

it’s not a device or system problem, because if I fire up the google maps application while inside, or with fine location disabled, then I still get my coarse location, even if gps fix is completely out of the question…

i will now retry the Hardware/GPS sample app while removing android permission for FINE data, but I have little hope it will help.

EDIT : just tried… if you remove the FINE location android permission, the Hardware/GPS sample app doesn’t report any location at all… pretty much what I expected :frowning:

As of now it seems Corona is currently unable to support my “indoor app”

(btw. this is not just pointing fingers, I can see that many latest apps often ignore coarse location. For example the Samsung’s original Clock+Weather widget also doesn’t update unless I go outside and get a GPS fix – the weather part of the widget doesn’t know my location and will therefore not update the weather data either… which is basically quite similar to what I want to do in my app.

so I’m not throwing blame around, just venting my frustration :frowning: )

Are you sure your Android device’s location services (under settings) doesn’t have coarse location disabled?

It’s usually a checkbox named “Use WiFi Location”.

yes, they are allowed, you can trust me i made sure of that. see the screenshots from HTC, Samsung and ASUS device.

also as I stated, if i run the  Google Maps app, the coarse location is retrieved normally (indoors without any GPS available), so that confirms the service in system works fine.

it’s only in corona that it doesn’t report anything for some reason. if you say it should work, maybe it’s possible there is a bug on android version that ignores coarse location and only uses fine location? I don’t want to imply…but I work in a mobile development company, so I know these things can sometimes happen :slight_smile:

Alright, so I have been investigating further, and have some news.

Thanks to the fact I work in a mobile dev company, I have access to more devices for testing, so I went on to try it more.

I modified the Hardware/GPS example app with:

  • added : system.setLocationAccuracy(3000)  into main.lua
  • removed : _ “android.permission.ACCESS_FINE_LOCATION”,  _  from build.settings

I built the APK, and tried it on various devices, and it seems that on some it works, on some it doesn’t. My current results :

Coarse location WORKING (indoors and even with GPS turned off) on:

…for these, the correct location shows up in about 3-4 seconds after I start the app.

  • HTC Desire X (android 4.1.1)
  • Huawei Ascend Y300 (android 4.1.1)
  • Sony Xperia L (android 4.2.2)
  • Samsung Galaxy Express (android 4.1.2)
  • Samsung Galaxy S3 (android 4.3)
  • LG (google) Nexus 4  (with developer preview Android 5.0)
  • Samsung Galaxy S4 (android 4.4.2)
  • Prestigio Multipad PMP5770D (android 4.1.1)
  • Samsung Galaxy S4 Mini (android 4.2.2)   — started working after multiple system reboots and repeated changing location settings on&off
  • Acer Iconia B1-710 (android  4.1.2)  — also started working after multiple system reboots and repeated changing location settings on&off
  • HTC Desire S  (custom rom android 4.1)  — same as above
  • ASUS Transformer TF101 (Android 4.0.4)   — same as above

Coarse location NOT WORKING (i never get any location)

  • HTC Desire S  (custom rom android 4.1)
  • ASUS Transformer TF101 (Android 4.0.4)
  • Samsung Galaxy S4 Mini (android 4.2.2)
  • Acer Iconia B1-710 (android  4.1.2)

*** all non working devices fixed as above. see EDIT 3 below.

So now the problem seems to be device specific, or maybe OS build specific… I will try to get even more devices, test further and report back.

EDIT : OK I am unsure what happened, but I restarted my S4 mini a couple of times, turned the location settings on and off on each checkbox, also a few times on and off again… and suddenly it started working even on this device…

EDIT2 : same thing happened with the Acer Iconia… a few reboots, few on&off clicks on the location checkboxes, and now i got the location available…

EDIT 3 - resolution - so I managed to get even the remaining two devices to read the coarse data. The trick, if it’s not working is to follow these steps :

  1. go to location settings, and turn everything off (gps, network, cellular, wifi location, whatever checkbox you’ve got there).

  2. turn everything on again.

  3. REBOOT THE DEVICE.

after these three steps, even the last devices finally got the Coarse location data.

So obviously not exactly a Corona issue but more of an Android issue in general.

I guess I will have to hope my users will not run into the same problems, because I can’t explain all this to them.  Maybe I’ll do a location check and if that fails, show some error message with the explanation, and an option to enter city manually… but i still can expect they will be pissed… android users love to complain.  (and i am the prime example :D)

thanks for everyone who joined in the discussion, hope you have learned a bit just as I did here. maybe it will also help someone in the future.

Thanks for posting your results.  Interesting info for sure.  It sounds like this might be a bug with the Android OS, a fork of the OS, or perhaps a driver issue.  Apparently, other Android developers have been running into this issue as well in Android 4.x as can be seen here…

   https://code.google.com/p/android/issues/detail?id=57707

This is a real bummer.  Well, we’ll keep our eyes peeled for any potential work-arounds in the future.

happy to help. honestly i’m just lucky i can get to test on more devices… if i just had the one phone as a true indie, i’d probably just give up.

let us know if you find any improvements in the future, because, as stated, even the devices that needed the 3-step fix and reboot, were reporting coarse location fine into Google Maps… it was all the other apps that had trouble - corona app, but also the Samsung clock&weather widget. As i said before, that one always needed GPS to work. From today, it’s loading weather data even when i turn GPS off :slight_smile:

edit: just read through the code.google posts… so it’s almost a year old bug yet google hasn’t fiven any statement nor any fix :(  seem’s we’re boned, unless we figure out how to use the same interface as Google Maps, which seems to be the only thing that works reliably.

It looks like Google offers a work-around via their Google Play Services library, which is what the Google Maps app uses, but that’s only a solution for apps that target the Google Play store because it requires the Google Play Store app to be present.  It’s useless if you’re targeting another app store such as Amazon.

yes, i pretty much got that it’s going to by true google play services limited, but it is a workaround for largest portion of android devices anyway - most androids are google’s, not Amazon’s :slight_smile:

so maybe an temporary workaround in future Corona releases would be to implement a simple logic that will say that if you’re building for Android to Google Play store, it would use the play services fix… and if not, it will revert back to the classical approach ?

until google fixes the issue (cause obviously it’s gonna be a long, long time)

Following up: are there please any plans to implement the google play services location method in future Corona releases?

I understand that it won’t fix for Amazon and some other special devices, however on most Androids this would fix the issue.

Besides this is no longer a “system bug” - meaning, Google has ZERO intention to fix this, as they introduced the new method for location and do not want to support the old one anymore. They want developers to use the google play services method, which will be the only one they will support in the future.

They are not going to go back to deprecated functions that they do not wish to support anymore.

Corona shouldn’t therefore hang on to old methods either and need to evolve with the platform as well.

Can you please put this in some kind of future release plans so there is an actual ETA on a fix which would make coarse location on Android usable again?

Thank you.

Joe.

Unfortunately no.  We’re actually drowning in feature/change requests at the moment, particularly with the upcoming iOS8 and iPhone changes, making this a lower priority.  As in, I’m sorry to say, we have much more hotly demanded tasks to be completed.  So, we can’t give you an ETA.

In my opinion, you should enable fine/gps location support.  If you don’t get a reading within a couple minutes, request the end-user to go outside to get a GPS lock.  That’s the best I can offer at the moment.

I understand that there are other requests, just saying this is more of a fix than a new feature, even if it’s low priority, it would be good to put it on a backlog to fix in the future.

as for your suggestion, I stated in one of my first post that it is a no-no.  What I’m trying to build is an app that the user should be using mostly in the morning before he goes out of his house, so telling him to go out, wait for location and then come back would basically just give me bad reviews and make the people say the app is useless.

I will for the time being have to avoid this by trying the location and if not available i will need to ask people to input their city manually, storing it and hoping it doesn’t change too often…

but it is an inconvenience to the user - good apps are defined by details and ease of use - basically a good UX. This will go against it.

So iPhone users should be fine, as for android users, I would have obviously large portion of unsatisfied users.

What I was looking for was if there is something i can look forward to as in the future this might get fixed.

Even if it’s next summer, better late than never.

I understand if exact ETA can’t be given, I’ll be glad if we at least knew that this is not going to be forgotten as a bug that nobody cares about fixing ever. :slight_smile:

Thank you.

I don’t believe this is possible with Corona SDK.  It would be possible with Corona Enterprise where you could reach into the native SDK’s to do things.

Rob