Finding current region with lat long in offline mode - ios

I am currently working on an app which requires the current region in which the user is in.The worst part is app is completely off line.
My logic :
1.Take a screen shot of the city draw squares on that.
Store square 4 points (lat long values taken with respect to map) in DB.
With the lat long values got from gps i can easily find out lat lont belongs to what reason.
I am just wondering if anybody can suggest me better idea to work my app offline.
Thank you in advance ..

You will probably find you have problems getting a location if you have no network access. iOS uses assisted-GPS, which allows the device to both lock onto GPS satellites much faster than it might otherwise take, and also pull in other data from the network to quickly determine location.
Without network access you may not get a location reported back at all, especially if the app was being used indoors (vanilla GPS reception is typically very bad without line of sight). If you do get a location it may take several minutes for an accurate enough reading to be provided.

you can use the RouteMe library which is based on OpenStreetMap. this allows to download map data in advance.
If you want to work with screenshots (from a legal source) then you use the Helmert transformation to transform between gps and picture-pixel coordinazes.
you need at least 3 points in the picture-map for which you now the lat,lon coordinates.

Related

Determine whether user is at a specific location

What's the best way to determine whether the user is at a specific location, i.e. at a gas station?
I've implemented an approach where the app is listening for major location changes until the user get's close enough to a location. Then the app switches to the more accurate location updates (kCLLocationAccuracyBest). It then checks if the user is close enough, and if so, I consider this as a "check-in". This works quite well. If the user moves away from our location of interest, I switch back to the major location updates to save energy.
This works as the user does not live or work within the first threshold (I currently use 300 meters). This situation drains the user's battery for no reason. If I set this threshold to low, the major location updates might not be accurate enough to detect the user in front of our location.
I'm using MKLocalSearchRequest to find all the places of interest in close proximity to the user.
So, I assume there are better ways. Any suggestions?
Thanks!
– Flo
iBeacons are the low power way if that fits your use case. http://en.m.wikipedia.org/wiki/IBeacon Is a suprisingly good overview
They are reasonably cheap, and can be simulated with computer software

iOS NearBy devices

Hi I am creating two apps where each app needs to know the location of the other app. I am using corelocation for that. However I am not sure whats the best/efficient way of getting the nearby devices. I can create a database with co-ordinates using parsi api. However I think that would be a lot of work to calculate the shortest distance every few minutes. Any ideas? I have a map for each app and i want to display the shortest distance between the two users on the map.I am using google maps api for ios
The API to calculate distance is pretty lightweight. Internally you use the Haversine formula to calculate distance including the curvature of the Earth. From the iOS perspective though you simply do this:
CLLocation* previousPoint = [self.allLocations objectAtIndex:i-1];
CLLocation* currentPoint = [self.allLocations objectAtIndex:i];
CLLocationDistance distanceFromPrevPoint = [previousPoint distanceFromLocation:currentPoint];
You can easily iterate over the other devices in the zone. If you want to reduce the number of calculations, you could only calculate distances to devices in the same base latitude longitude (ignore minutes and seconds).
Since you're using Parse, you should be able to do a PFQuery for all place objects within a given range. See the documentation here: https://www.parse.com/docs/ios_guide#geo/iOS (Geo Queries)
If they're close enough (~30 meters) you can use iBeacons.
What would work the best depends on your particular app's needs.
Edit: Since you said your distance is too far, iBeacons won't work.
The brute-force way to do this is to run through all connected devices and calculate the (Pythagorean) distance to each one, and select the ones that are within your distance threshold. That's very time-consuming however.
Instead you might want to have each device report some sort of region code for each location (State? County? Zip code?) as the location changes. You'd use geocoding to generate the region information. You could have the reporting devices do the geocoding themselves, so they are only responsible for updating location information for a single device and you don't bog down doing geocoding. You'd report lat/long and region information to the server as it changes, with a "choke" to only report changes on significant changes, or once per minute, whichever is LESS frequent. (I remember reading in the docs that you are only supposed to submit a small number of geocoding calls or you get locked out and/or your app gets rejected.)
You'd collect the data in a central server.
Then you could start by requesting other users that match your current region (and possibly nearby regions) and then do distance calculations only on that small subset of your data that matches the region code.

How do I know what GPS provider is using

I developing iOS application working with user location. The question is
"I would like to know that current location is come from Wifi or 3g or else? I would like to know the provider."
Is this possible? I googled around with no luck.
Thanks in advance.
You can't know how it is getting it, but you can know the accuracy of the locations you receive. Every CLLocation object has a horizontalAccuracy property that you can check. It will indicate the margin of error in meters. Also it has a verticalAccuracy property for 3D locations.
First if the device has GPS and you choose CLLLocationAcuracyBest or BestForNavigation, then GPS is used as Location provider all the time.
If you dont want to use that modes, you can distuniguish the location Provider by:
Only GPS delivers the attributes "course/heading" and "speed".
No other (WLAN, GSM-cell) can provice course and speed.
Altitude theoretically could be provided by GSM-Cell (or Wlan), so it could be unsafe to use the altitude as GPS identification hint. I do not recomend using altitude.
While standing still course will also be invalid even when using GPS, while speed will be a valid 0.
A further very good working solution is to use the horicontal accuracy < 40 condition.
GSM Cell will have hor. accuracy much higher than 40m, eg. 1000m.
if you have horicontal accuracy < 30 its for sure form GPS
if you have a valid course: Its for sure from GPS
if you have a valid speed: Its for sure from GPS
In all other cases its a bad position, and it usually is not necarry for further finding wheter from bad GPS or good Wlan / GSM
I ran in to the same problem like you few months ago.
I found some similar questions on stackoverflow that have the same answers like:
your device will automatically send updated location information to your app wherether it from GPS, wifi, EDGE, 3G ...
depends on your code when you init your CLLocationManager

Firefox OS device gps

I'm currently searching a way for device using firefox OS to communicate with device's gps, so it can get the exact location positioning, rather than the w3c geolocation api which is not as accurate as gps realtime.. Thanks!
Simple answer: it isn't possible to access the "device's GPS" directly. You only have the Geolocation API that you already know.
Long answer: My experience with it is not bad at all. So, I think only of two possibilities for not getting "exact location positioning", as you name it:
maybe you're not using the right options to get a precise position. In this case, you could tweak your options a bit to get better results;
maybe you're not waiting until the underlying software can use your GPS instead of some less accurate instrument/estimation (like Wi-Fi positioning estimation).
It can be a combination of both =P
In the first case, you can verify if you're using enableHighAccuracy, like this:
navigator.geolocation.watchPosition(
successCallback,
errorCallback,
{ enableHighAccuracy: true }
);
This will ask the browser for better results, as the standard indicates. Watch out that this may use more battery, and this may not be available anyway. This may take more time too, which is related to my other observation.
In the second case, you may be using a value for timeout that is too small, and maybe it's combined with a maximumAge that may be too high.
If maximumAge is high and timeout is small, you get an out dated position, as there won't be enough time to get a new position and you accept an old one.
If both are small, you'll start to get lots of TIMEOUT errors (the value is 3), as there'll be no positions for you.
You need to find the right balance between all 3 options to get the best positions. And you have to be patient sometimes.
Play with all 3 options and take a look at the errors you get. They'll tell you a lot about your issue getting precise and accurate coordinates.
The position object has some attributes that may come in handy to analyze what's happaning:
the position.timestamp attribute will tell you how old that position object is. If this is old, you know you should tweak the options
the position.coords.accuracy attribute will tell you the accuracy level of the lat/long coordinates. If this is too big (it's in meters), you know you should tweak the options
If you wait forever, on a place where the GPS should work well (say, outdoors, on a clean field), and you keep getting inaccurate results, maybe you can't do much better anyway. I'd say it's not possible anyway, with your software+hardware =(
As of now, Firefox OS only has support for GPS positioning (with the latest addition of A-GPS in the mix). That results in the fact, that most of the time you will have to wait from 1 to several minutes at least for the GPS module to acquire lock on your location, and you will need clear look at the sky for the lock to be acquired.
That said, after a lock is acquired, by using the right settings in the call itself (like setting the enableHighAccuracy flag to true) the GPS should provide as accurate position as any other device would.
Right now cell-based and wifi-based geolocation is not available in the current version of the OS (1.0.1 or 1.1.0, either) but is in the pipeline.
You can use the Geolocation API Firefox OS or Google Maps (I do not remember where I got it)

CLLocationManager not very accurate inital updates

This is stated in CLLocationManager class reference:
When requesting high-accuracy location data, the initial event delivered by the location service may not have the accuracy you requested.
This is really affecting my app. How can I make sure that the location found is the one with the correct accuracy?
I tried to use the 4th or 5th update rather than first retrieved location but this is not a good solution. Any idea?
You should check the accuracy of the updates, CLLocation
contains a property horizontalAccuracy which you can use to check the accuracy.
When the CLLocation has an accuracy that you find accurate enough you use and ignore al others.
Als you should tel CLLocationManager your desired accuracy. To do this set the desiredAccuracy property in CLLocationManager.
I think you will have to live with that. That's how Apple implemented it. Getting a fine grained position takes time, just think about how long any windshield-mounted GPS devices in cars take to fix up their position.
So instead of letting your application wait for a longer time, they provide with what accuracy is available almost immediately, based on cell-towers and WiFi hotspots in the vicinity. Only when there has been a more reliable GPS fix will they call into your app again and let you know.
In the end, it is just a question of where the waiting for the fine-grained position is: In your app, where you have the chance of doing something with the more coarse-grained data you get quickly, or in their framework with no chance for apps to do anything useful in the meantime. I think, letting you decide is the better choice.
Depending on the type of app, you could have a map that automatically zooms in deeper as soon as better position data comes in, draw a smaller circle around the position you are expecting etc. For the end user, nothing's worse than waiting without getting any feedback. So even though this is probably not the answer you would have liked, I advise to make the best of it from a user's perspective.

Resources