|
我用ajax调用页面时,地图marker不会显示。单独打开文件又可以显示。代码如下:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>自定义点标记图标</title>
<link rel="stylesheet" type="text/css" href="http://developer.amap.com/Public/css/demo.Default.css" />
<script language="javascript" src="http://webapi.amap.com/maps?v=1.3&key=f4a23f5dfee394e16f1198f01cf4feed"></script>
</head>
<body>
<div id="iCenter"></div>
</body>
</html>
<script language="javascript">
var mapObj2;
var marker2;
//初始化地图对象,加载地图
function mapInit2(){
mapObj2 = new AMap.Map("iCenter",{
//二维地图显示视口
view: new AMap.View2D({
center:new AMap.LngLat(112.48365,23.061232),//地图中心点
zoom:13 //地图显示的缩放级别
})
});
//添加点标记,并使用自己的icon
addmarker2();
}
//在地图上添加点标记函数
function addmarker2(){
marker2=new AMap.Marker({
icon:new AMap.Icon({ //复杂图标
size:new AMap.Size(28,37),//图标大小
image:"http://webapi.amap.com/images/custom_a_j.png", //大图地址
imageOffset:new AMap.Pixel(-28,0)//相对于大图的取图位置
}),
position:new AMap.LngLat(112.48365,23.061232)
});
marker2.setMap(mapObj2); //在地图上添加点
}
mapInit2();
</script>
|
|