【发布时间】: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