-3

Since most browsers have HTML5 enabled, tracking the current device and displaying it on the map is possible, however, is there a function for a webapp based device, to update a central database on it's location?

My theory is that a user can POST a form to upload its coordinates, but this would cause it to be slightly of a hassle.

Is there a way, preferably automated, to track a user's geolocation in real time, through a web app?

Before all the downvotes come in, I would like to clarify that yes, I am able to track myself and get geolocation working on my device. What my intention is, is to track others and receive the value, something like a tracker.

edit: totally saw the downvote coming

Olivier Moindrot
  • 27,908
  • 11
  • 92
  • 91
Ponilz
  • 109
  • 1
  • 13

2 Answers2

4

If you want to track other users in real time, you have to use a websocket. For example if you are using node.js as your backend then simply use a package named socket.io, it handles all the heavy duty work for connecting one client to another client

Example code

ClientSide

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');

   // Maybe send some location data through a click of a button
  socket.emit('sendLocation', { latitude: 232.33, longtitude: 232323.33 });

</script>

Serverside

io.on('connection', function(socket) {
   // Socket is listening waiting for the client to send something to the server
   socket.on('sendLocation', function(data) {
       // Emit to everyone that is connected via socket.io
       io.emit('sendToEveryone', data);
   });
});

So the order is

1) Client emit

2) Server listen then will emit it again to the targeted user or all user

Hope it helps

airsoftFreak
  • 1,450
  • 5
  • 34
  • 64
  • `// Maybe send some location data through a click of a button socket.emit('sendLocation', { latitude: 232.33, longtitude: 232323.33 });` I cannot remember if it is possible, but if you are sending through a click of a button, it would not be possible to live track automatically. However, if I were to add a client side timer than automatically sends the data, would that be feasible? Am reading through the documentation now, will get back to you later! :) – Ponilz Jun 24 '16 at 05:24
  • This looks like a great option! Just went through the documentation and this seems to be something! Will wait for a few more responses but yours seem to be perfect! Never knew there was such this as a web socket :) – Ponilz Jun 24 '16 at 05:30
  • It is feasible, it all depends on how you create your clientside. Im actually building a similar thing but in ios as the clientside instead. So in my application, user A could see user B in real time on google maps. I just keep emitting the location of user B to every other users including user A in the system. – airsoftFreak Jun 24 '16 at 12:30
  • if you are using an app called trello, they are using part socket.io part built in websocket, but I really don't know what are they using nowadays since they have grown so big. http://blog.fogcreek.com/the-trello-tech-stack/ – airsoftFreak Jun 24 '16 at 12:31
1
  • I thing this can do it. (for app android)

1: Use spirit level or compass from device android enter link description here

2: When change "spirit level" + timer 1minus -> submit to address new to server.

  • And if web app you can use refresh browser after frame time.

    < html>< head>< meta http-equiv="refresh" content="3">< /head>

Chau Tran
  • 11
  • 3