关于HTML 5中的地理定位 [英] About Geolocation in HTML 5

查看:160
本文介绍了关于HTML 5中的地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



据我所知,这是HTML 5兼容浏览器的一项新功能,并且位置是通过使用连接的WiFi网络的某种功能(我希望我没有做任何愚蠢的假设)。



我想知道的是这个整体过程完全正常:


  • 为什么只在HTML 5中?

  • Firefox为什么/如何问我使用Google地图分享我的位置?

  • 什么是正常的精度值得您信赖?
  • 如何在我的网站中实现此功能?



在此先感谢!

解决方案

<它是如何工作的?



当您访问Firefox中的位置感知网站时,浏览器会询问您是否要共享您的位置。



如果您同意,Firefox收集有关附近电线的信息较少的接入点和您的计算机的IP地址,并将通过将此信息发送到 Google位置服务(Firefox中的默认地理位置服务)。该位置估计然后与请求的网站共享。 (来源



地点的准确度如何?



精确度因地点而异。在某些地方,地理位置服务提供商可能能够提供几米之内的位置。但是,在其他领域,这可能远不止于此。所有地点均被视为估计数,因为所提供地点的准确性无法保证。 (来源



<对我而言,Firefox报告说我距离我的真实位置约10公里。



如何在我的网站中使用此功能?



您可以这样做:

  if(navigator .geolocation){
navigator.geolocation.getCurrentPosition(function(position){

alert(position.coords.latitude +,+ position.coords.longitude);

//根据您的需要使用纬度和位置,您可以在Google地图上设置一个标记
//,例如
});
}
else {
alert(地理定位服务不被你的浏览器支持);



$ b

你可以在这里看到一个在线演示:(需要支持地理位置的浏览器,例如Firefox 3.1b3)/ b $ b $ / b

Google Maps can now pinpoint my location with street precision with the help of Firefox.

I understand this is a new feature of HTML 5 compatible browsers and that the location is fetched by using some sort of feature of the connected WiFi network (I hope I'm not making any silly assumptions).

What I intend to know is how this whole process exactly works:

  • Why only in HTML 5?
  • Why / how does Firefox ask me to share my location with Google Maps?
  • What is the normal precision one can count on?
  • How can I implement this feature in my websites?

Thanks in advance!

解决方案

How does it work?

When you visit a location-aware website in Firefox, the browser will ask you if you want to share your location.

If you consent, Firefox gathers information about nearby wireless access points and your computer’s IP address, and will get an estimate of your location by sending this information to Google Location Services (the default geolocation service in Firefox). That location estimate is then shared with the requesting website. (Source)

How accurate are the locations?

Accuracy varies greatly from location to location. In some places, the geolocation service providers may be able to provide a location to within a few meters. However, in other areas it might be much more than that. All locations are to be considered estimates as there is no guarantee on the accuracy of the locations provided. (Source)

In my case, Firefox reports that I am about 10km away from my real location.

How do I use this feature in my website?

You would do something like this:

if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(function(position) {  

        alert(position.coords.latitude + ", " + position.coords.longitude);

        // Use the latitude and location as you wish. You may set a marker
        // on Google Maps, for example.
    }); 
} 
else {
    alert("Geolocation services are not supported by your browser.");
}  

You can see an online demo here: Firefox HTML 5 Geolocation Demo (Requires a geolocation-aware browser such as Firefox 3.1b3.)

这篇关于关于HTML 5中的地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆