Possible? Use Google Maps/GPS to tell how long someone has been in a location? - iphone

I'm thinking about building an iphone app that would use the GPS feature to track where someone is and for how long. I realize I could probably get the current location from the iphone from a website but the only way I'm familiar with is using ajax calls, etc (Sorry if this is a rather newbie concept) but I fear that would bog down my servers with constant calls to track time. Is there a better way to do this? Any resources I could consult on this idea/concept? Is it even plausible at this point?
I'm more versed in php/mysql but trying to branch out on some new ideas I've had. Any help would be greatly appreciated!

You could keep a local datastore then only send updates to the server when the app detects that the user has moved. I'm pretty sure that would work and on the server side you just work out the last time a user checked in and then compare that against the current time to see how long they have been somewhere. The only technical issue I can see with this is that this requires the user to have the iphone on and the app open the ENTIRE time they are somewhere, which would mean the iphone is now just a rather expensive GPS tracker with a built in phone!

you could store user locations on a local list on the iphone and once an hour you send the list with location/timesptamp pairs to server.
As James Raybould says, you can compute on server how long a user stayed inside a range for a given position. And also by sending data once an hour... not each time the iphone detects that user moved, then you save your server for continuously pings.

Related

Is it possible to get distance from user location to specific location in background in IOS?

I need to calculate distance from user location to specific location, when the app is in background, and get a local notification based on that.
Background location tracking is totally possible, and I have already done that, but is it possible to execute a block of code, containing some condition checking and based on that update and get a local notification?
I am not getting any proper solution. Is there any way to do so?
Can you help me please?
Yeah, you can definitely do that. I'm doing it in an app right now. Use significant location changes, or regions, as previously suggested, to keep the pressure off the users battery as much as possible.
We observe regions (and significant location changes where regions are not supported by the device) then check a few things and fire off a local notification if needs be.
We started with a basic prototype to prove the concept and I highly recommend that approach as a way to get familiar with the location and notification frameworks.
Start with the Location Awareness Programming Guide. Most everything you need to know is in there. (Most things that aren't in there are simply impossible for an AppStore app.) See also Tracking the User's Location in the iOS App Programming Guide.
The best tool for what you're describing is likely "Shape-Based Regions." You can basically draw a box on a map and say "when the user enters or leaves this box, let me know." If at all possible, this is the tool you should use. It has the least impact on battery life.
If you absolutely cannot solve the problem any other way, it is legal to request background location delivery with startUpdatingLocation (and the appropriate background mode in Info.plist; see the above docs). An app that tracks your route while you hike would be be appropriate for this kind of setup. But you should avoid it if at all possible since it's a major battery drain.
You will want to update for significant locations in the background: http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/. Then you will want to create a location notification based on that.
My issue is that I am not sure if you can create a local notification in the background.

Ensuring correct date/time

we are creating a location-enabled app where users use this app to record certain events in the field.
The important part of the event data is when an event happened. This is no issue when user is online, but we also support situations when user is offline (by remembering & later syncing events).
There could be situations when users are offline and they change the time on the phone, so that event times are wrongly recorded.
So, what would be the best way to ensure we get a correct time, independent of user actions, given that device could be offline. Some ideas:
GPS time. Is it possible to acquire it?
Tracking system time changes made by user?
Any other idea?
Note: time does need second accuracy, approximately minute accuracy would be ok.
Note2: we are creating mobile apps for Android and iPhone, so I'm interested for generic solutions and also solutions that are specific to any of those two platforms.
I, personally, wouldn't worry so much about this scenario. The liklihood of someone intentionally changing the time on their Android (which periodically throughout the day syncs to a time server automatically) while offline seems low to me. That being said, the only way I could see compensating for this is to keep a service running in the background that keeps a running tally of the seconds passed since recording the location data offline. Once uploaded to your servers you could use the elapsed seconds to calculate a time offset from current UTC time. It's an awful lot to go through, but it would work.
GPS time is an interesting idea, but Android allows users of the SDK to send mock locations to their devices. I'm not sure you could reliably track changes to system time either, and even if you could you'd be capturing them after the fact without the current real time as context.
We use GPS times in our app for very similar reasons. Since our users are in different time zones and we want local times, we define from our server what time zone they are in at installation time (they don't move very far). Hadn't thought of the mock GPS locations, but you would need to be a fairly advanced user to do that.

iphone sdk system time vs user time

I have an app that requires me to take an action after some period of time. For example, if an user hasn't been inside the app in few weeks, when the user eventually starts the app, I have to ask them to put in a special code that was given to them when they installed this app. (this is an in-house app and i am being required to do this due to security concerns)
I am using the [NSDate date] method to retrieve the date when the user logs in and save it into a database. I compare this saved date next time they open up the app and see how long its been since their last login. The problem is that [NSDate date] gives the time that is effected by the time settings that can be changed manually by the user in the native settings app. As you can probably tell, this causes lots of problems to my situation. If the user is suppose to be put the special code after 3 weeks of inactivity, he can cause the app to show this screen by modifying the time in the native settings app or worse, get away from it by setting the time to a previous date that will be within 3 weeks of his activity.
Is there a way to get the "system time" instead of the "user time"? I have looked into mach_absolute_time() but this gets reset after restart of the device. Since the time of inactivity I will be comparing against is pretty large, chances are device would have been restarted by then. I also thought of using network connection to get the time from servers outside the app, but lots of users won't have access to wifi where they use their iPads. That will be my last resort solution if i can't find anything else. Because of their location during usage, I am trying to use everything on the device itself.
Am I overlooking something simple here? this seems too simple of a problem to not have an answer. Please guide me toward the right direction. Thank you in advance.
Why not query a remote server for the time - lots of NTP servers about or just make a simple HTTP request to a php script on your own server. Of course if your app is likely never to be connected to the internet that could be a problem, but once you have a 3rd party time its quite easy to guess if the user has been playing with the clock.
If this is an inhouse app (so you aren't constrained by Apples approval process), you could mark your app as doing some background stuff (voip or receiving location updates), so that the app will always be active and you'd be able to update some sort of an "unused" counter. Voip app will even be restarted by the OS after device reboot.
But of course it'll drain the battery somewhat.
Either: make having the actual time an essential feature of your app. This way the users will have a need to keep the time of the device current and can't go back three weeks
Or: mark the code as expired and save this information before the app informs the user. This will stop most user from setting the time back. Most will try once or twice, see that the app stays disabled and will give up.
You can also save the timestamp of the last successful execution and if that is more than a reasonable time frame in the future (remember summer/winter time) then consider it a "hack attempt". Put a CRC check (or whatever obscure idea you come up with) on that timestamp and save it too and you will stop a large number of script kiddies.
You can never stop the diehard hacker who search actively for every trick you might have put into the app. Just focus on the "average" user.

Can I send locations to a server in background on Iphone?

I'm looking for the answer to my question but it's quite difficult for me. I would like to keep connected to the server in background sending location of the iphone with ios4.
I`m really sad because I think that multitasking of apple is not real multitasking, in fact they only keep the state of the app but they don't allow it to run in background.
May be somebody knows if is possible to send a call by http every 30 or 60 minutes...
Please, any help would be very appreciated. Thanks in advance
Depends on it you are looking to track the user -- like Grindr does (this is not bad, per se, it just must be disclosed to the user -- and PLEASE remember to power down the GPS equipment if you really do not need to do this at certain times).
You are able to register for several different types of "location" registrations, wake up (enough to do something with that information) and wait until the next update.
Look at Multitasking under "Receiving Location Events in the Background". It will give you all the info you need. Short answer: iOS4 may not support what you think you need for this, but it, in fact, does support everything required to do what you are asking.
link text (Membership required)
I know this is an old question, but below is a relevant statement from the Core Location documentation regarding background handling of "significant location change":
Because your application is in the
background, it should do minimal work
and avoid any tasks (such as querying
the network) that might prevent it
from returning before the allocated
time expires. If it does not, your
application may be terminated.
link to documentation containing quote
I'm not sure if the quoted statement is saying to avoid all network "queries", but I think a quick POST of the location should be fine.
I did this but my app got rejected due to this last week. I used the ios5 SDK.
There's a good answer to this question by user RedBlueThing here.
The answer is basically yes, you can process network requests, but you might need to ask the OS for more time to accomplish the task.

iPhone OS: implementing your own achievements, how do I do it?

I'm working on a game where really the only game part is (at least right now) that the user can unlock achievements as she does various things throughout the game. I have a database that can keep track of certain user actions and record how many times a user does something but I'm having trouble figuring out the best way to architect the app so that I have to do the least amount of work. Kind of suck with the timing because gamecenter is not ready and it seems like openfeint is changing gears, but maybe I'm wrong. I'd prefer to do everything "in house" if it is not too ridiculous. looking for suggestions.
One of the parts I'm having the most trouble figuring out is how to manage the state of all the achievements. NSuserdefaults vs. core data vs. a flat data file.
Also is there anyway to send a notification if a core data field reaches a certain amount?
Thanks,
Nick
Are you keeping the achievements on the device only, or also on the server? On the device, there is no reason not to use Core Data.
Using Core Data, you could use KVO on your model properties to monitor when certain values reach a new achievements.