K_Reverter的网页开发记录

要么不做,要么就当作艺术品来做!

导航

在Google Maps之中显示访问者的位置

        今天顺便看了看微软出的地图msn virtualearth觉得有地名标注确实好很多,不知道Google什么时候给地图加上地名标注啊

        不过我看到一个好玩的东西,就是Microsoft Location Finder确实比较好玩,也就查看了一下代码,从MSN网站分离到我的网站了,反正偷微软的东西也不是第一回了。

        下面是代码和简单说明:

 1//获得返回值并输出
 2    function SetAutoLocateViewport(lat, lng, zoom, pin, message)
 3    
{
 4        document.getElementById('MyLocate').innerHTML = "您的地理位置是(<a href='#' onclick='map.centerAndZoom(new GPoint("+lng+","+lat+"),zoom);'>点击查看该位置</a>):<br/><li/>经度:<strong>" + lng + "</strong><li/>纬度:<strong>"+lat + "</strong>"
;
 5    }

 6//调用本函数启动获得用户地理坐标的过程
 7    function AutoLocate()
 8    
{
 9        var wifi=
GetWiFiControl();
10        if
(wifi)
11        
{
12            try

13            {
14                var results =
 wifi.GetLocation();
15                if(results&&results.length>0
)
16                    {eval(results);return;}

17            }

18            catch(ex)
19                {}

20        }

21        var s = document.createElement('script');
22        s.src = "http://virtualearth.msn.com/WiFiIPService/locate.ashx?pos="
;
23
        document.body.appendChild(s);
24    }

25//取得ActiveX控件
26    function GetWiFiControl()
27    
{
28        var wifi=null
;
29        try

30        {
31            wifi=new ActiveXObject("WiFiScanner"
);
32        }

33        catch(e)
34        
{
35            try

36            {
37                wifi=new ActiveXObject("Microsoft.MapPoint.WiFiScanner.1"
);
38            }

39            catch(e)
40            
{
41                try

42                {
43                    wifi=new WiFiScanner("Microsoft.MapPoint.WiFiScanner.1"
);
44                }

45                catch(e)
46                {}

47            }

48        }

49        return wifi;
50    }

        原理其实全在那个http://virtualearth.msn.com/WiFiIPService/locate.ashx?pos=上面,可以通过网址访问这个路径查看该JS文件,比如:

1SetAutoLocateViewport(22.54749912114.101667310false, 'Virtual Earth has determined your location by using your computer\'s IP address.');

        微软服务器端原理也就和QQ察看用户地理位置差不多,只不过返回的是一个地理坐标而不是地名。

posted on 2005-10-17 18:36  K_Reverter  阅读(326)  评论(2)    收藏  举报