views:

41

answers:

1

Many posts address this for iPhone apps, but I need to know how to do this for javascript on a web page.

My specific problem is that I want to track the device's location over a long period of time (say a car trip). This becomes a problem when the device sleeps (and maybe during a phone call, I haven't tried that case yet).

I'm open to any ideas, including preventing sleep mode (but since I'm in Safari, I'm not sure how much control I'd have to do that).

+2  A: 

You can't. Web pages do not execute javascript unless (1) the page is frontmost and (2) Safari is actually active. Safari does not remain active when the device is asleep.

If you think about it, this functionality would be a massive privacy breech. Image how you'd feel if you visited a web page that then secretly tracked the your location even when the device was off! You'd be very angry. Even if you could do this technologically, you'd get lynched if people found out you did it.

Location info is closely guarded for reasons of privacy and physical safety (think about stalkers and your web page.) That is why you get a dialog asking to use the Location Manager the first time you get a location.

TechZen
I don't think privacy is an issue. Whenever you try to access Location Services in Mobile Safari, doesn't the user have to click "okay"? To me that signifies consent. Well... to me anyway.
Andrew
Thanks for the reply, though I don't think that it's as much of a privacy breach as you suggest. The user's always informed and should have no expectation that "sleep" is the same as "off". But that's a matter of opinion I guess.
Sid
I would be concerned by any remote scripting that could activate such the location manager. Given security issues with web sites, you couldn't even be sure that the site you thought was requesting your location was actually sending the code. Having a web page that ran and tracked your location in the background would be even more dangerous even if you had to give it permission to start. How many pages do you have loaded right now in mobile Safari and how long have they been there? It would be easy to open an hole and leave it open.
TechZen