根据游客的ip信息获得地理信息,定位当地地图
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script language="javascript" type="text/javascript" src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
<!--调用谷歌地图js,zoom缩放倍数,center中心,mapTypeId地图类型-->
<script type="text/javascript" src="http://ditu.google.com/maps/api/js?sensor=true"></script>
<script language="javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(39.9493, 116.3975);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var address = remote_ip_info.country+remote_ip_info.province+remote_ip_info.city;
document.getElementById('add').innerHTML = "欢迎来自:"+address+"的朋友!";
var img='http://avatar.csdn.net/B/9/A/1_youacai.jpg';
if (geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title:'你现在的位置',
// icon:img
});
}
});
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
</script>
</head>
<body onload="initialize()">
<div id="add" style=" height:26px;color:#F00;font-size: 18pt;"></div>
<div id="map_canvas" style="width: 380px; height: 280px;"></div>
</body>
</html>