How to show multiple users location in iOS project live? - ios

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)

Related

Is it a good idea to keep updating users current location?

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.

How to set geolocations automatically and create a geofence in the background in swift?

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.

Core Location skips user movements with CLVisit monitoring turned on

The app I'm working on records information about places where user spends most of his/her time. Core Location's Visits monitoring fulfil all it's requirements in location information absolutely.
While testing this app our QA-engineers revealed evidence that Core Location misses Visits for unknown reason. And this is not a result of low location accuracy. Core Location starts skipping locations registered before without any problems.
To make things clear we've run the test. I installed on his phone our app and example app: https://github.com/steveschauer/TestCLVisit
After 3 days of testing we compared locations from our app, sample app and information from Settings->Privacy->Location Services->System Services->Frequent Locations.
Information from all sources was equal. So we can say that it's not an issue of our app.
But while all locations registered at first day was correct, many locations of second and third day were missed. Only few of them were registered.
Is it normal behaviour for Visits Monitoring?
What could be a reason of such skips?
Does anybody have negative or positive experience of Visits monitoring?
Yes, I faced some similar issues while using CLVisit API. There is also an article from NSHipster, which describe some issues with CLVists and these are still present in iOS 10. It essentially goes on to say that if you want infrastructure that extremely precise don't use CLVisit.
From our experience, CLVisit is not all that precise. While start and end times are generally accurate within a minute or two, lines get blurred at the edges of what is and what is not a visit. Ducking into a corner coffee shop for a minute might not trigger a visit, but waiting at a particularly long traffic light might.

Getting which contacts are close to my current location?

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.

how to find users location when a photo is taken and display+save in a UIMapView

was just wondering how i would basically go about finding the user's location and then displaying this in an un-editable UImapView. This would be used to location stamp photos and videos taken within the app and must still be displayed whilst the app is open.Just as a disclaimer i am not asking anyone to sit and write this code for me (but feel free to if you want) i was just hoping that someone else may have already done this and so might provide their code as a reference. thanks for any help you can provide
As rokjarc says, you need to break this into pieces.
The camera app that's built into iOS already has the option to save location data into your photos.
Are you saying that you want to be able embed location information in pictures that you take from within your app?
You have at least 3 different things you need to read about:
CLLocationManager. You would create an instance of the location manager and ask it to start updating your location. It takes a while to settle down, so you would want to start it when your app is launched. You'll want to fine-tune the settings so it only notifies you on fairly large location changes to conserve battery. The location manager is an async library, so you start it updating, then wait for it to notify you, and parse the location updates it gives you to make sure they are current/accurate enough.
Next, map kit. You would need to add an MKMapView to your app's views, and set it up to display to a window. you could either use the option that shows the user's location automatically, or use location manager information to change the map region and/or create a map annotation showing the user's current location.
Third, you will need to figure out how to save location metadata to the images you take. That's not something I've done, so I don't have any specific help for you.

Resources