I'm experimenting with an app for my own use, and trying to find an energy efficient way to get the Contacts whose addresses are close to my current location.
There are about 100 people in my Contacts list each located in another town, maybe 5-60 km apart. Essentially after I've visited about 5-6 of them I'm running out of time and I just want the next two or three to be really close to my location.
What I'm doing now, requesting directions by selecting a Contact manually and seeing how much time it would take to get there, which is fine... But as the client list grows I have trouble remembering which ones are close and I keep selecting them and never get it right.
I tried storing them in an NSDictionary and grouping them by locality but it would be great to have a simple radar like report where the program would "see" which points are close just as one is able to figure out immediately by looking at a map whith 20 placemarks.
Any suggestions?
How does -distanceToLocation: (iOS Developer Library) sound to you?
From the comments I understand that you have the locations of all contacts. So you just need to loop through the contacts, get the distance to your current location and compare them...
You could possibly make an array or dictionary of CLLocation and CLLocationDistance objects and sort them by the distance.
Related
I am trying to develop an app that would show the location of multiple users near you on a map in real time. Me and my friend were thinking of getting the users location every 1 min, then upload their current location to a database, then update that on the map, and show it on other people's map. Now we realize that this would consume so much data and time from the user, also that would create so much calling to the database which we are trying to limit. So my question is, how would I show multiple users location on the map in real time? Think of uber or lyft and how they display the driver's location and also many other driver's location to the user. How did they accomplish that or if there is away of creating a similar thing without the strain on the user's data.
Steps to be followed -
Get location of the user not after every 1 minute or specific time but get location as per user moves. Get their location by using Significant-Change Location.
To get multiple users data - you must be storing data of other users, so get those data in background thread. Don't use main thread to get data but use main thread to display the data.
If you want store data into local database, so that if user is offline he does not looses any data.
PS: Start small scale then go for large scale. Don't think of handling data into large scale like uber at first. So start with 5 users and updating data into application every specific time( this is not for fetching user location but to showing data of users)
In my app I have to send a Lat/Long to my server and in return I get an array of Data within the range of 10-15m and I have to add the people on the map. I can achieve this by few different scenarios:
1- I can load all the Data within the range of 100m and only make a request if user searches outside this range.
2- I can use the method "startUpdatingLocation" whenever user searches for a location and when user is on that location I can call "stopUpdatingLocation". The Last location will be saved and used to send for the request.
3- Or I can keep the location updating and when user clicks on the button to make the request I can get the last lat/lang.
They might sound similar but I want to know which scenario saves less memory and data usage.
It depends on how often the users are performing searches, and if their searches are geographically close to one another. Approach #1 uses more memory because it has to store a larger array of data (which, depending on what the data looks like, probably isn't a very big deal) but it might save data usage in the long run if you have to perform less queries to your server. It depends on user behavior.
Approaches #2 and #3 don't seem to be any different in terms of data usage and memory since you are describing different ways of keeping the latitude and longitude of an user updated. This doesn't seem to be related to the data usage of your server.
For a current project I am trying to create a geofence around all hospitals and emergency rooms. I am trying to make the app alert the user if he/she enters a geofence of a hospital. I have I good idea of how to set geofences but I am unsure how to automatically set them on all hospitals.
Thanks!
First and foremost: you cannot set this up as a one-time geofence. There can only be 20 active geofences at any time from your app. There are a lot more than 20 hospitals in the world.
I don't know if you have a list of hospitals already, or if that's the question. If you want to get a somewhat accurate list, then you'll want to make a MKLocalSearch to find ones nearby. If this isn't accurate enough, you'll have to compile your own database of locations.
You can use the results to set up geofences for the 20 closest hospitals.
You can then use CLLocationManager.startMonitoringSignificantLocationChanges() to detect when the device has moved substantially (this often happens when you change cell towers). You can then search again and reestablish geofences for the current 20 closest hospitals.
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.
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.