Search code examples
node.jsgeolocation

Node Server Geolocation


Is there a way for a Node server to work out it's accurate (i.e. GPS) location without using the HTML Geolocation API from the browser? It also needs to be disconnected from the internet, i.e not depend on some external lookup.

In my case I have a server which is a laptop, not connected to the internet, and physically moving around a location. When the client connects to the server, the server needs to already know where it is, the client may not be in the same location. Imagine the client starting up a map and drawing two dots, one with the location of the server and the other with the location of the client.

Basically, does an equivalent to navigator.geolocation.getCurrentPosition exist for a server?


Solution

  • The only way to do this is to have some GPS or GNSS hardware attached. After that, it's very easy.

    Almost all of those GPS/GNSS units show up as a serial port. You can open the serial port using whatever package is appropriate for whatever system you're using. From there, a handful of protocols are used but NMEA is the most common and easiest to deal with. NMEA data looks like this:

    $GNRMC,143909.00,A,5107.0020216,N,11402.3294835,W,0.036,348.3,210307,0.0,E,A*31
    

    In this example, the latitude is 51 degrees, 7.0017737 minutes North, 114 degrees, 02.3291611 minutes West. There are NPM packages available for parsing.