Node Server Geolocation

六月ゝ 毕业季﹏ 提交于 2021-02-10 21:53:52

问题


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?


回答1:


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.




回答2:


There is something called IP-based Geo-location.It basically is a mapping of an IP address to a geographic location of an Internet-connected machine. Check this Medium Article to find some IP Geo location APIs



来源:https://stackoverflow.com/questions/58975710/node-server-geolocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!