google map marker 显示

lotuszyh 发布于 2015/09/04 11:43
阅读 311
收藏 0

最近在研究google map api,但为什么现在添加的marker无法显示了呢,请大侠指点,代码如下:
<!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>

加载中
返回顶部
顶部