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 bees 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).
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 bees 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).
Share Improve this question asked Jul 4, 2010 at 13:45 SidSid 731 silver badge3 bronze badges 5- I don't know for sure, but doesn't the iPhone stay on when cradled? You could show a pop-up telling users to keep their iphone plugged in; that would solve the car-trip users. As for the rest, you'd be killing their batteries in no time flat. GPS and internet network access really hurt battery life. – Andrew Commented Jul 4, 2010 at 14:31
- I'm aware of the ramifactions. The user would be well aware that they are being tracked, it's the exclusive purpose of the webpage. So assume that they will have the webpage up as the frontmost page in Safari, and that Safari is active. Also I've noticed that a few iterations of "watchPosition" do occur after the device goes to sleep. But after those few (about 5) it stops. – Sid Commented Jul 4, 2010 at 14:39
- @Andrew I'll try this in my car. It didn't work in my stereo. – Sid Commented Jul 4, 2010 at 14:39
- Also, setting auto-lock to never is a great workaround. Is there a way to set my phone to never auto-lock when docked? I don't mind asking users to configure their phones this way. Heck I'd prefer requiring them to be charging. – Sid Commented Jul 4, 2010 at 15:12
- 1 I'm sorry! Now that I look, it seems you can't do it. I got my Touch back with firmware 2.1.2 and I'm certain it had that option ("Stay on while docked: [Yes/No]"), but now, that option is gone. Even plugged in, it shuts off automatically. I wonder why on earth they removed this feature. I've not heard anyone plete about screen burn-in. – Andrew Commented Jul 4, 2010 at 16:12
1 Answer
Reset to default 8You 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 breach. Imagine how you'd feel if you visited a web page that then secretly tracked your location even when your device was off! You'd be very angry. Even if you could do this technologically, people may be upset if they 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.