【问题标题】:why does geocomplete not trigger bounds_changed event?为什么 geocomplete 不触发 bounds_changed 事件?
【发布时间】:2014-05-28 09:38:38
【问题描述】:

我有一个占据整个屏幕大小的谷歌地图。有一个带有地理完整文本字段的顶部栏,这样我就可以输入地名,地图就会移动到那个地方。但是,问题是它无法触发 bounds_changed 事件。

第二个问题是,当地图第一次加载时,我无法拖动它(没有出现手形图标)。只有在我使用地理完整字段移动到其他地方之后,我才能拖动地图。以下是我用过的相关代码sn-p。

$(document).ready ->
 google.maps.event.addListener window.map, "bounds_changed", ->
   // Here I fire an ajax request to retrieve some data and display it in a custom overlay.
 if navigator.geolocation
navigator.geolocation.getCurrentPosition(set_user_location,error, { 'enableHighAccuracy' : 'true' })
  set_user_location = (position) ->
mapOptions =
  center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
  zoom: 14
window.map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions)
$('.countries-dropdown').geocomplete
  map: '#map-canvas'
  mapOptions: { scrollwheel: true }
  bounds: true
.bind 'geocode:result', (event,result) ->
  console.log 'result'
  console.log result
.bind 'geocode:error', (event,result) ->
  console.log 'error'

如果以上信息不够,请发表评论。谢谢。

【问题讨论】:

    标签: jquery google-maps google-maps-api-3 geolocation geocomplete


    【解决方案1】:

    没关系。我自己修复了这个错误。只需要提供 window.map 对象来代替选择器。也就是说,而不是这个

    $('.countries-dropdown').geocomplete
    map: '#map-canvas'
    

    用过这个

    $('.countries-dropdown').geocomplete
    map: window.map
    

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 2021-07-16
      • 2011-12-03
      • 2014-12-06
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多