代码如下:
几点注意一下:
1、获取网络地址的方式为 http://fw.qq.com/ipaddress,返回内容格式为var IPData = new Array("xx.xxx.xxx.xx","","广东省","深圳市");
2、在init中根据qq返回的变量去添加地址。
3、其实也可以通过request去获取远端用户IP,并不一定要通过fw.qq.com去获取。
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE> Google Map By:Pop</TITLE>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″/>
<scrip t type=”text/javascrip t” src=”http://fw.qq.com/ipaddress” charset=”GBK”></script>
<script type=”text/javascript” src=”http://www.google.com/jsapi?key=abc”></script>
<script type=”text/javascript” src=”http://maps.google.com/maps?file=api&v=2&sensor=true&key=abc”></script>
<script type=”text/javascript”>
function loadMaps(address) {
var map = new google.maps.Map2(document.getElementById(“map”));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var geocoder = new GClientGeocoder();
geocoder.getLatLng( address,
function(point) {
if (!point) {
alert(address + ” not found”);
map.setCenter(new GLatLng(35.8616600, 104.1953970), 4);
} else {
map.setCenter(point, 12);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
function init() {
loadMaps(IPData.join(‘ ‘));
}
</script>
</HEAD>
<BODY οnlοad=”init()” οnunlοad=”GUnload()”>
<div id=”map” style=”width: 800px; height: 600px”></div>
</BODY>
</HTML>