Search code examples
gpswebrequestsmartphone

Smartphone web page to send user's GPS coordinates to server


I'm a former professional developer from years ago, (VB.NET and old school ASP) but it's been a few years now I own a driving school so my skills are a bit out of date but still useful for my needs. For my driving school business I've created a scheduling application. It's a winforms application. It populates a database of course, which is used by web pages to display any instructor's daily schedule. Instructors view their schedules on their smartphones. Everything I just described either already works, or soon will.

Within the smartphone web page (which I refer to falsely as an "app" because I want it to be compatible with most smartphones) I would like to add the capability for the instructor to "Check in" to each appointment, and then to "check out" after each appointment by clicking ("touching") somewhere on the page.

The action of "checking in or out" would submit a web page request, which sends to my database a record that includes: Time of day, instructor ID, and GPS coordinates of the smartphone.

THE PURPOSE: Reports can be generated from this data, revealing whether instructors arrive for lessons on time, and also confirming they did not finish a lesson early, and further confirming that when they "checked in" they were within a certain distance of the student's house. (This prevents them from "faking a check-in" while en-route but still far away.) Thus I can confirm my employees are providing appointments on-time, and giving lessons of appropriate length without need for installing GPS tracking devices in my cars. (Those things are expensive!)

FINALLY MY QUESTION: I don't know how a web page can obtain the smartphone's current GPS coordinates such that they can be included within a subsequent web request. For example, a hidden field could be populated with longitude/latitude before the web request is submitted. Javascript is an acceptable approach if that works. I prefer a method that works for as many smartphones as reasonably possible. Can web pages on smartphones get this data? How?


Solution

  • Use HTML5 Geolocation that is supported my modern browsers. Use navigator.geolocation property via javascript and then send its coordinates through hidden fields, ajax or whatever you prefer. You can check how it works in your browser console:

    navigator.geolocation.getCurrentPosition(function(position) { 
      alert(position.coords.longitude)
    })
    

    See more info here http://www.w3schools.com/html/html5_geolocation.asp