How to track the device location (iOS and Android) device using Phonegap

view story

http://stackoverflow.com – I would like to know when a user arrives or leaves certain location. I was trying to do this using the wireless network (check for mobile devices), but I couldn't for several reasons. 1) I needed real time updates or every 1 - 5 min of the information about which devices are connected and which devices have just disconnected. 2) I had very high ping from my PC to my iPhone on the same network (still don't know why). Now I want to do it using geolocation from a Phonegap application (running in the background) suspended on iOS or running in the background in Android. Any help would be apprec (HowTos)