开发者

How navigator.geolocation.getCurrentPosition gets location coordinates of a client browser

开发者 https://www.devze.com 2023-04-05 08:33 出处:网络
I am using browser API for geolocation like below (codes written below are just for demo) Clie开发者_运维问答nt Script using jQuery

I am using browser API for geolocation like below (codes written below are just for demo)

Clie开发者_运维问答nt Script using jQuery

       $(function () {
            $('#link-getlocation').click(function () {

                navigator.geolocation.getCurrentPosition(function(loc){
                       alert(loc.coords.latitude + ', ' + loc.coords.longitude);
                });                    
            });
        });

Html

<a href="javascript:" id="link-getlocation">Get Location</a>

Demo

http://jsfiddle.net/yhHnD/1/

My question is how browser detects the location coordinates of the user


It depends on the capabilities of the client browser.

  • If the device running the browser has GPS (f.ex. a mobile phone), it generally uses GPS based locating
  • If the device is on a WLAN, the browser can utilize WLAN location data (eg. via Google Location Services)
  • Otherwise it most likely will use a GeoIP database

Most of these depend on OS and browser support and can vary between browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号