利用Google的jsapi确定客户端所在的位置
Google的jsapi提供了许多有用的功能,其中有一个就是对客户端的检测,用很简单的几句Javascript就可以确定浏览者的地理位置,从而可以进一步做有针对性的处理。下面是一个示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Google API Test</title> </head> <body> <script src="http://www.google.com/jsapi" language="javascript"></script> <script language="javascript"> if (google.loader.ClientLocation != null) { document.write("您的位置是: " + google.loader.ClientLocation.address.city + "," + google.loader.ClientLocation.address.region); } else { document.write("Google无法确定你的位置"); } </script> </body> </html> |
打开上面的网页,我得到的结果是:
您的位置是: Xi'an,Shaanxi