Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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 如何在Google Maps API上禁用箭头键平移_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 如何在Google Maps API上禁用箭头键平移

Javascript 如何在Google Maps API上禁用箭头键平移,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,使用网页上的GoogleMapsAPI,我可以使用键盘的上/下和右/左箭头键来平移地图。我希望允许用户像往常一样通过鼠标拖动/平移地图,但希望禁用在单击地图后按键盘箭头进行的平移。我该怎么做 作为背景,我正在使用网页上的箭头键执行其他功能,以在HTML列表中上下移动,并且不希望在用户按下箭头键时地图四处移动。您可以将MapOptions中的选项设置为false,以禁用地图上的键盘操作 谢谢,我会试试这个,但它看起来在这里有效! <!DOCTYPE html> <html>

使用网页上的GoogleMapsAPI,我可以使用键盘的上/下和右/左箭头键来平移地图。我希望允许用户像往常一样通过鼠标拖动/平移地图,但希望禁用在单击地图后按键盘箭头进行的平移。我该怎么做

作为背景,我正在使用网页上的箭头键执行其他功能,以在HTML列表中上下移动,并且不希望在用户按下箭头键时地图四处移动。

您可以将MapOptions中的选项设置为false,以禁用地图上的键盘操作


谢谢,我会试试这个,但它看起来在这里有效!
<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -34.397, lng: 150.644},
          keyboardShortcuts: false,
          gestureHandling: "greedy",
          zoom: 8
        });
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?callback=initMap&key=YOUR_KEY"
    async defer></script>
  </body>
</html>