Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的ImageMapType实现stucks_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 我的ImageMapType实现stucks

Javascript 我的ImageMapType实现stucks,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正在尝试实现我自己的基本图像映射。但我的代码出错了。它在我突出显示的行(带**)上出错。地图退回到默认路线图。错误信息只是“错误”,我不知道发生了什么 你能帮忙调查一下吗 非常感谢 我的javascript代码: <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"&g

我正在尝试实现我自己的基本图像映射。但我的代码出错了。它在我突出显示的行(带**)上出错。地图退回到默认路线图。错误信息只是“错误”,我不知道发生了什么

你能帮忙调查一下吗

非常感谢

我的javascript代码:

  <html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map-canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=my-api-key&sensor=true">
    </script>
    <script>

      // custom map type
      var mapTypeOptions = {
        getTileUrl: function(coord, zoom) {
           return 'http://http://placehold.it/256x256.gif';
        },
        tileSize: new google.maps.Size(256, 256),
        name: 'Some Place',
      };
      var customMapType = new google.maps.ImageMapType(mapTypeOptions);

      // initalize function
      function initialize() {

        // try to create a new map with custom map type
        var mapOptions = {
          center: new google.maps.LatLng(22.33173, 114.16061),
          zoom: 17,
          minZoom: 17,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
        };

        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
        map.mapTypes.set('ssp', customMapType); // ****
        map.setMapTypeId('ssp');    
      }
      google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
  <div id="map-canvas"/>
  </body>
  </html>

html{高度:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%}
//自定义地图类型
var mapTypeOptions={
getTileUrl:函数(坐标、缩放){
返回'http://http://placehold.it/256x256.gif';
},
tileSize:new google.maps.Size(256256),
名字:“某地”,
};
var customMapType=new google.maps.ImageMapType(mapTypeOptions);
//初始化函数
函数初始化(){
//尝试使用自定义贴图类型创建新贴图
变量映射选项={
中心:新google.maps.LatLng(22.33173114.16061),
缩放:17,
minZoom:17,
mapTypeId:google.maps.mapTypeId.ROADMAP,
};
var map=new google.maps.map(document.getElementById(“地图画布”),mapOptions);
map.mapTypes.set('ssp',customMapType);//****
map.setMapTypeId('ssp');
}
google.maps.event.addDomListener(窗口“加载”,初始化);

看起来您缺少配置设置

mapTypeControlOptions: {
  mapTypeIds: ["ssp"]
}
此外,还需要为
mapTypeOptions
定义
maxzoom

请参见示例:

还存在一些验证错误,请在关闭对象之前删除尾随逗号