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

作者提到微软的地图msn virtualearth有地名标注很好,期望Google地图也添加。还介绍了好玩的Microsoft Location Finder,查看其代码并从MSN网站分离到自己网站,说明了服务器端原理与QQ查地理位置类似,返回地理坐标。

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

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

        下面是代码和简单说明:

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

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

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

17ExpandedSubBlockEnd.gif            }

18InBlock.gif            catch(ex)
19ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{}

20ExpandedSubBlockEnd.gif        }

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

25None.gif//取得ActiveX控件
26None.gif    function  GetWiFiControl()
27ExpandedBlockStart.gifContractedBlock.gif    dot.gif
{
28InBlock.gif        var wifi=null
;
29InBlock.gif        try

30ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
31InBlock.gif            wifi=new ActiveXObject("WiFiScanner"
);
32ExpandedSubBlockEnd.gif        }

33InBlock.gif        catch(e)
34ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
{
35InBlock.gif            try

36ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
37InBlock.gif                wifi=new ActiveXObject("Microsoft.MapPoint.WiFiScanner.1"
);
38ExpandedSubBlockEnd.gif            }

39InBlock.gif            catch(e)
40ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif
{
41InBlock.gif                try

42ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
43InBlock.gif                    wifi=new WiFiScanner("Microsoft.MapPoint.WiFiScanner.1"
);
44ExpandedSubBlockEnd.gif                }

45InBlock.gif                catch(e)
46ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{}

47ExpandedSubBlockEnd.gif            }

48ExpandedSubBlockEnd.gif        }

49InBlock.gif        return wifi;
50ExpandedBlockEnd.gif    }

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值