<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>//添加谷歌地图的引用js
<script type="text/javascript">
var map;
function initialize() {
var myLatlng = new google.maps.LatLng( x,y );//x,y是坐标
var myOptions = {
zoom: 5, //缩放比例
center: myLatlng, //显示在中心
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); // 找到地图显示的div,显示地图
标单个点: var marker = new google.maps.Marker({ position: myLatlng, title: "鸿印全装" });
marker.setMap(map);
标多个点:
后台循环(01是坐标,2是名字 3是循环i 45是{}) var location{3} = new google.maps.LatLng({0},{1});
var marker{3} = new google.maps.Marker({4}
position: location{3},
map: map
{5});
marker{3}.setTitle('{2}'); //给地图标点,可以标多个点
attachSecretMessage(marker{3}, {3}) //标点可点击进入网址
}
function attachSecretMessage(marker, number) {
google.maps.event.addListener(marker, 'click', function() {
window.open("/Dealers/Detail-"+number+".html");//进入相应的网址
});
}
</script>
另一种显示一个方框的详细地址
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
下面那段代码是弹出一个层显示地址
var infowindow = new google.maps.InfoWindow(
{ content: '<%=sContent %>',//后台显示层的代码
position: myLatLng
});
infowindow.open(map);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map);
});
<body onload="initialize() "><div style="WIDTH: 500; HEIGHT: 500" id=map_canvas></div></body></html>//初始化上面的代码,在body的onload事件中。