I am working on web analytics, we are using node.js
in server side, we are sending the data using http request(express framework)
.
我正在进行网络分析,我们在服务器端使用node.js,我们使用http请求(快速框架)发送数据。
Requirement
:Have to find the latitude and longitude of the visitor.
要求:必须找到访客的经纬度。
My question is how to find the latitude and longitude in node.js
? Any framework available?
我的问题是如何在node.js中找到纬度和经度?有可用的框架吗?
2 个解决方案
#1
4
I strongly recommend to use the HTML5 geolocation API inside the browser and then send visitor location information to your server – that's way more accurate than using geolocation from IP addresses on the server-side. You will be getting the location of the ISPs, which can be quite far away, and in addition the IP-to-location databases aren't always up to date with the latest changes, so you might won't get any data for a particular IP address.
我强烈建议在浏览器中使用HTML5地理位置API,然后将访问者位置信息发送到您的服务器 - 这比使用服务器端IP地址的地理位置更准确。您将获得ISP的位置,这可能相当远,而且IP到位数据库并不总是最新的更新,因此您可能无法获得任何数据特定的IP地址。
To find out more about this topic take a look at MaxMind, which offers a popular IP-to-location database published some statistics on its database: GeoIP City Accuracy for Selected Countries
要了解有关此主题的更多信息,请查看MaxMind,它提供了一个流行的IP到位数据库,在其数据库中发布了一些统计数据:GeoIP城市准确性选定国家
Here's a great example of using navigator.geolocation
:
这是使用navigator.geolocation的一个很好的例子:
- Real-Time Geolocation Service with Node.js
- Node.js的实时地理定位服务
#2
0
If the visitor is visiting your site via a browser, then you are asking the question on the wrong technology.
Node.js is a serverside technology, which means it can't access the user's geolocation directly.
如果访问者通过浏览器访问您的网站,那么您问的是关于错误技术的问题。 Node.js是一种服务器端技术,这意味着它无法直接访问用户的地理位置。
What you should be asking is how to get geolocation using javascript on the clientside, and then simply send that information to your server via Ajax.
That question is very easy to answer: http://www.w3schools.com/html/html5_geolocation.asp . There are ofcourse libraries that will ease the use of this.
您应该问的是如何在客户端使用javascript获取地理位置,然后只需通过Ajax将该信息发送到您的服务器。这个问题很容易回答:http://www.w3schools.com/html/html5_geolocation.asp。有一些课程库可以轻松使用它。
If you can't, don't want to, or don't want to bother getting the information clientSide, then you can try and match the IP (which is what Maxmind does, though I'm not sure if they'll give you the longitude and latitide or just a city name).
However these will not be exact, especially if your visitors are using devices with geolocation capabilities (such as mobile phones).
如果你不能,不想,或者不想打扰获取信息clientSide,那么你可以尝试匹配IP(这是Maxmind所做的,虽然我不确定他们是否会给你经度和latitide或只是一个城市名称)。但是,这些并不准确,特别是如果您的访问者使用具有地理定位功能的设备(例如移动电话)。
#1
4
I strongly recommend to use the HTML5 geolocation API inside the browser and then send visitor location information to your server – that's way more accurate than using geolocation from IP addresses on the server-side. You will be getting the location of the ISPs, which can be quite far away, and in addition the IP-to-location databases aren't always up to date with the latest changes, so you might won't get any data for a particular IP address.
我强烈建议在浏览器中使用HTML5地理位置API,然后将访问者位置信息发送到您的服务器 - 这比使用服务器端IP地址的地理位置更准确。您将获得ISP的位置,这可能相当远,而且IP到位数据库并不总是最新的更新,因此您可能无法获得任何数据特定的IP地址。
To find out more about this topic take a look at MaxMind, which offers a popular IP-to-location database published some statistics on its database: GeoIP City Accuracy for Selected Countries
要了解有关此主题的更多信息,请查看MaxMind,它提供了一个流行的IP到位数据库,在其数据库中发布了一些统计数据:GeoIP城市准确性选定国家
Here's a great example of using navigator.geolocation
:
这是使用navigator.geolocation的一个很好的例子:
- Real-Time Geolocation Service with Node.js
- Node.js的实时地理定位服务
#2
0
If the visitor is visiting your site via a browser, then you are asking the question on the wrong technology.
Node.js is a serverside technology, which means it can't access the user's geolocation directly.
如果访问者通过浏览器访问您的网站,那么您问的是关于错误技术的问题。 Node.js是一种服务器端技术,这意味着它无法直接访问用户的地理位置。
What you should be asking is how to get geolocation using javascript on the clientside, and then simply send that information to your server via Ajax.
That question is very easy to answer: http://www.w3schools.com/html/html5_geolocation.asp . There are ofcourse libraries that will ease the use of this.
您应该问的是如何在客户端使用javascript获取地理位置,然后只需通过Ajax将该信息发送到您的服务器。这个问题很容易回答:http://www.w3schools.com/html/html5_geolocation.asp。有一些课程库可以轻松使用它。
If you can't, don't want to, or don't want to bother getting the information clientSide, then you can try and match the IP (which is what Maxmind does, though I'm not sure if they'll give you the longitude and latitide or just a city name).
However these will not be exact, especially if your visitors are using devices with geolocation capabilities (such as mobile phones).
如果你不能,不想,或者不想打扰获取信息clientSide,那么你可以尝试匹配IP(这是Maxmind所做的,虽然我不确定他们是否会给你经度和latitide或只是一个城市名称)。但是,这些并不准确,特别是如果您的访问者使用具有地理定位功能的设备(例如移动电话)。