Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

firefox - About Geolocation in HTML 5

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...