Best practice for sending live location data to server from iPhone - iphone

I want to develop an application for the iphone, that tracks the current position of the user in "realtime" and sends this data to a sql database on a webserver by a web service, so I will be able to have a consistent database where the registered users a currently positioned.
This is raising some questions on how to do this in an efficient way.
1) Shall I really update the GPS data in realtime on the server? Isn't this to "heavy" regarding energy consumption on the iphone? Maybe once a minute does it as well? What are best practices here when I want to be as accurate as possible?
2) What if there a maybe 1000 users at once.... is this still efficient to update a database with the current GPS data simultaneously?
Thank you in advance
Sebastian

Sending GPS data at regular time intervals will put extra load on the system unnecessarily and it is not optimal.
A better way to track the user is to send data only when the user has moved outside a circle of radius R from the last reported location.
That way a user moving in a car at 60 mph on a highway and one walking at 0.1 mph in a park will both be tracked accurately.
Users are known to stop moving when they sit down to eat, go to the bathroom or sleep.

Related

Can cloud firestore realistically be used for syncing a game between players?

I'm looking at using cloud firestore to sync a multiplayer web game between players. However, this game involves continuous motion, like a player dragging a piece from one place to another. This would involve a stream of writes as its position changes. Given that the free plan is 20k free writes per day, and 20k writes can be done by a dozen players in a few minutes in this case, I worry that the cost would rapidly spiral out of control.
Is it impossible to do this sort of thing with firestore? I'm basically talking about a continuous websocket connection keeping the game data synced between players.
The limits of Firestore are well-documented. You haven't really said what hard limits you're concerned about exceeding. The only thing you've indicated is limits regarding the perpetual free tier, which can be easily exceeded by simply paying for the product based on your usage.
If you're not willing to pay for the service based on your needs, then you should probably look for another service. If you are willing to pay, then you need to do the math to figure out what your specific needs are, and if they can be met by the documented limits.
In the absence of more specific information about what you're trying to achieve, there's not much else that can be said.

Mobile phone app event timing synchronization

I'm trying to coordinate a triggered event across many smartphones within as small a time-frame as possible (ideally have them start within half a second or less of each other).
The problem:
From my experience, the local time value on the devices cant be relied on, and additionally latency can contribute to issues with syncing a value for the current time (imagine trying to get the updated time from some remote source and eventually approaching a decently close idea of the current time locally based on that remote source, ideally within a fraction of a second of said source).
Are there any established techniques, mechanisms, or more accurate sources of some time value reference point that would allow for a planned event to be triggered on multiple devices within a fraction of a second of one another? The more I search, the more I realize this is not a trivial issue, however I thought it would be worth it to query the great minds of stackoverflow.
Thanks in advance for any and all help.
I've developed a technology that achieves synchronization of smartphones down to 10 milliseconds. Each devices takes the UTC time from many clocks and makes a non-trivial convolution.
I have applied this to a massive event (http://massivesymphony.org) and I'm now providing the technology for several corporate events.
In case you are interested in more details, my contact is
José I. Latorre
Dept. of Physics, U. Barcelona
j.i.latorre#gmail.com

iOS Find Other Nearby Devices (GPS locations)

I have an app that allows a user to transmit their location to a server. What I am trying to do is have the user press a button that will send a push notification to anyone with the app within lets say a 3 mile radius. Can someone give me an overview of how I can accomplish this.
The only way I could think of doing this is publishing the gps coords to a server. Then when the user presses "Send notif" a message gets sent to the server, then the server does some complex proximity search based upon the location and then returns the values to the user.
My problem is, I have no server-side experience and have no idea how to program a GPS search algorithm on the server.
Is there a way for me to do what I want without having to write code on a server? I am able to use Parse to store the GPS coordinates. I'd like to keep my server code to simply storing and retrieving values and handle everything else client side.
Thoughts?
Each device should send their GPS coordinates to the server periodically. I think you already have this step. The next step is to find devices that are near each other. This is fairly simple.
Distance Between Two Latitude and Longitude Points
However, if you have millions of devices, it will be a problem of scale if you compare each update to all the other devices. You might bucket the devices to a certain area. For example, you might bucket the updates into 100 square mile areas. When an update comes in you need to only compare to those devies in that bucket plus adjacent buckets if they are near the edge. This is just top of the head analysis but hopefully it will point you in the right direction.
If you really want to put all the load on the client (iOS) side:
Query the server for IDs and locations of all possible recipients for the push notification
Store ID and Location in custom object and put those in a NSArray or a NSSet
Then
//otherUsers is the NSArray or NSSet with custom objects
//currentLocation is the users current location
for(MYCustomUser * otherUser in otherUsers) {
if([currentLocation distanceFromLocation:[otherUser location]] < 4829) { //4828 == 3 Miles in Meters, so 4829 is 3 Miles + one Meter
//send msg to server to perform push notf. to user
}
}
Done...
you should put this in a NSOperationQueue so that is can run in background an is not blocking the device
But as bbarnhart said... it's not very wise to put all this on a device.

When to Cache the data

Q1) I am designing a iPhone app and want to know on what basis I should take the decision of caching data.
Q2) I have a huge data set which can change frequently. On my app I am showing the data under different categories and is planning to fetch the data from server when a particular category is tapped. This will reduce the data transfer. Also, this data can change frequently but I can store it for let say 30 minutes. What strategy should I take here? Should I store in core data or no caching all together and for each repetitive taps should hit the server?
Please suggest.
What does "hit" mean in this context? Asking the server whether your data is fresh or simply refetching it?
I would suggest that you cache a few MB or so, that you assume that data stays fresh for at least thirty seconds or so (depends on your scenario). If you want the application to feel very fluent, download everything that can be reached with two taps (or so) or less if it isn't yet cached after each tap (as long as that isn't too much data).
You might also want to include a less-data-mode for users who have a traffic-based-costs internet access.
It totally depends upon the frequency of new data. You can cache the data that's to be displayed at the application launch in all your tabs and then let the updated data flow when user makes request for new data.

Third party data delivery of lots of data

Does anyone know how sites that have a real-time feed of a lot of data work? I am referring to something like a stock site, where they can tell you in real time (well, 20 minute delay mostly, but still real-time - 20 minutes as I understand it).
They have thousands of data pieces delivered to them every second, I would imagine: MSFT 25.00 +.23 VOL 12000 ???? for each stock that had a change during some interval.
So, is there just a constant feed of small pushes going on? Or do you think a site will pull from the place that has the real data and say "give me all changes since 12:23:45 CST to now" type query?
I ask this because at work we might have a situation where we need to have at our application's fingertips real time information like this, and it won't make sense to hit our third party provider over and over and over again every second...
Generally there is a server/client protocol defined between the 2 parties. In the company I work for the connection is maintained at all times.
Here is info on real time data feeds to go with your stock example
NYSE,NASDAQ
It is common for data providers to also have FTP sites with (delayed) batched data. One that comes to mind is the NWS EMWIN
Sites like Twitter feed data to certain approved sites in real-time via XMPP (Wiki link).
In the broadest terms, a push model is going to be the best way of achieving "real time" transfer, particularly if you're talking about a large amount of data.
However you do always have a problem when using a purely push model of how to recover from missed data.
Depending on the nature of your data that may not be a problem (thinking of video delivery as an analogue, where the amount of data is huge but there is sufficient redundancy for it to recover from missing data). And if you have any control over the data you may be able to build some redundancy in. For example, on every change event you can provide absolute values rather than changes, or previous value and new value.
I've done this making an attempt to retrieve the stock quote from the source, and falling back to a timestamped on-disk cache of the quote when the main source fails or times out.