GPS Accuracy
Im running into an issue with my GPS accuracy. My code checks for Titanium.Geolocation.getCurrentPosition and if it errors itll spit out an alert asking for the GPS to be turned on. I'm using Android 2.1 and Titanium Mobile SDK 1.4.
This all works, but it seems like its using the network provider to pull the coordinates. I can never get it within a half mile of accuracy.
I'm using both
Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.PROVIDER_GPS;
yet nothing seems to be solving the issue, I'm not even seeing the GPS icon popping up in my status bar.
Is there a way to pop up an activity indicator while the device gets exact coordinates?
Any help would be greatly appreciated. Here is my current code.
http://pastie.org/1238167
1 Answer
-
Accepted Answer
First off, it doesn't look like you are actually setting the preferred provider or accuracy…..you simply are placing them in your code. Try something like:
Titanium.Geolocation.preferredProvider = Titanium.Geolocation.PROVIDER_GPS; Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; Titanium.Geolocation.distanceFilter = 10;
Also if you read through the documentation/this forum they tend to suggest that calling this method one time will not be sufficient for determining location. They recommend you get the location by continuously listening to the heading event (note this approach will drain battery as GPS doesn't get turned off). You can find an example in the Kitchen Sink.
Personally, I have moved all of my geolocation code into a function and simply called it twice with setTimeout. Using setTimeout has ensured that it wasn't called back to back….you should wait for one to have the time to finish the call before calling it again, setTimeout accomplish this. Having it called twice seems to provide the accuracy I need and also doesn't require me to continuously listen for the heading event and drain battery.
The activity indicator is not tied to the GPS. You simply create your own activity indicator & display it, then get your GPS coordinates, then when you are done hide the activity indicator.