【问题标题】:how to disable dropdown(?) on Google Maps infowindow如何禁用谷歌地图信息窗口上的下拉菜单(?)
【发布时间】:2014-11-21 03:28:20
【问题描述】:

我正在使用 Ruby on Rails,并且对 JavaScript 了解不多(当然,我的整体编码很差)。我自定义了 Google Maps API 并想制作 infowindow。然而,当我创建我的信息窗口时,“有时”下拉菜单会在桌面(而不是手机)中弹出。

我认为这不仅仅是 Google 地图的问题。我认为它可能是任何与 HTML、CSS 相关的问题,但毕竟不知道......这很奇怪,因为只有当餐厅的名称是某种类型(两个单词或带有一些数字的名称时)才会弹出下拉菜单,但我不能认识到确切的原因和区别是什么..)

# my_javascript.js

function googleMap() {
  var geocoder = new google.maps.Geocoder();
  var restAddr = document.getElementById('address').value;
  var restName = document.getElementById("name").value;
  geocoder.geocode( { 'address': restAddr}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var restLatLng = results[0].geometry.location

      var mapOptions = {
          zoom: 13,
          center: restLatLng
      };
      var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);

      var marker = new google.maps.Marker({
          map: map,
          position: restLatLng
      });

      var infoWindow = new google.maps.InfoWindow({
          //maxWidth: 100, it didn't work
          content: restName // **this part is the problem. When the restName is like "new york", "house 2"(some with one-digit(?)-number). but not when the restName is "new york stree" kind. **
      });
      infoWindow.open(map, marker);

    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}
window.onload = googleMap

这是我的视图文件。

# app/views/home/page.html.erb

<%= @rest.addr %>
<p>changed</p>

<input type="hidden" id="address" value="<%= @rest.addr %>">
<input type="hidden" id="name" value="<%= @rest.name %>">
<div id="map-canvas"></div>

谁能帮我提些建议?任何 cmets 都会对我很有帮助,让我了解更多关于编程的知识。谢谢!!

【问题讨论】:

    标签: javascript css ruby-on-rails google-maps


    【解决方案1】:

    您必须在 da DIV 中获取 infowindow 内容并使用 css 设置 div 样式。 在您的情况下,请执行 '&lt;div class="scrollFix"&gt;'+restName+'&lt;/div&gt;' 并将 div 属性设置为:

    .scrollFix {
        line-height: 1.35;
        overflow: hidden;
        white-space: nowrap;
    }
    

    这是一个工作示例: http://jsfiddle.net/veaz/7Zm8w/

    【讨论】:

    • 谢谢@Manuel!!我想不出将样式直接放入该信息窗口内容中。这对我来说是一个很好的教训,你的参考让我更容易理解。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 2013-08-05
    • 2016-07-10
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多