google map marker 显示

purplelotuszyh 2015-09-04 11:27:44
最近在研究google map api,但为什么maker无法显示?是目前google map受限制了吗?代码如下,请各位大侠指点。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Maps JavaScript API v3 Example: Image MapTypes</title>
<link href="mapfiles/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="mapapi.js"></script>
<script>
function tlen(len, mystr){
mystr = String(mystr);
var num = len - mystr.length;
for (var i = 0; i <= num; i++)
{
mystr = "0" + mystr;
}
return mystr;
};

function CoordMapType(tileSize) {
this.tileSize = tileSize;
}

CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
var div = ownerDocument.createElement('DIV');
var ymax = 1 << zoom;
var y = coord.y;
y = tlen(5,y);
var x = tlen(5,coord.x);
zoom = tlen(1,zoom+1);

div.innerHTML = y + "," + x + "," + zoom;
div.style.width = this.tileSize.width + 'px';
div.style.height = this.tileSize.height + 'px';
div.style.fontSize = '10';
div.style.borderStyle = 'solid';
div.style.borderWidth = '1px';
div.style.borderColor = '#AAAAAA';
return div;
};

function LocalMapType() {}
LocalMapType.prototype.tileSize = new google.maps.Size(256, 256);
LocalMapType.prototype.maxZoom = 20;
LocalMapType.prototype.minZoom = 0;
LocalMapType.prototype.name = "本地";
LocalMapType.prototype.alt = "显示本地地图";
LocalMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
var img = ownerDocument.createElement("img");
img.style.width = this.tileSize.width + "px";
img.style.height = this.tileSize.height + "px";

var ymax = 1 << zoom;
var y = coord.y;
y = tlen(5,y);
var x = tlen(5,coord.x);
zoom = tlen(1,zoom+1);
var strURL = "..\\data\\L" + zoom + "\\" + y + "-" + x + ".png";

img.src = strURL;
return img;
};

var localMapType = new LocalMapType();
function initialize() {
var myLatlng = new google.maps.LatLng(30, 103);
var myOptions = {
center: myLatlng,
zoom: 4,
streetViewControl: false,
mapTypeControlOptions: {
mapTypeIds: ["local", google.maps.MapTypeId.ROADMAP]
}
};

var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
//map.setMapTypeId('satellite');
//map.MapTypes.insertAt(0, moonMapType);
map.mapTypes.set('local', localMapType);
map.setMapTypeId('local');
map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(256, 256)));
var marker = new google.maps.Marker({
position: myLatlng,
map: map,

});


}

</script>
</head>
<body onLoad="initialize()">
<div id="map_canvas" style="width: 640px; height: 480px;"></div>
</body>
</html>[
...全文
51 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,888

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧