【问题标题】:Google Maps Infowindow Position谷歌地图信息窗口位置
【发布时间】:2013-04-24 02:21:11
【问题描述】:

我对这段代码有疑问,当我点击一个标记时,我希望信息窗口在该标记的位置打开。

当我点击每个标记时,它们都会在同一个位置打开。

代码:

App.map = function (data, cb) {
  App.getData(App.config.LFMurl(), function (data) {
    App.processData(data, function(arr){      
    var mapOptions = {
      zoom: 12,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions)

  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude)

      var marker

      $.each(arr, function (index, item) {            
        marker = new google.maps.Marker({
          position: new google.maps.LatLng(item.lat, item.long),
          map: map,              
          animation: google.maps.Animation.DROP        
        })
        google.maps.event.addListener(marker, 'click', function(){                            
          var infowindow = new google.maps.InfoWindow({                
            map: map,
            position: new google.maps.LatLng(item.lat, item.long),                                
            content: item.title
          })
          infowindow.open(map, this)
          console.log(item.artist)              
        })
      }) 

      map.setCenter(pos)
    }, function() {
      handleNoGeolocation(true)          
    })
  } else {      
    handleNoGeolocation(false) // Browser som inte stödjer geolocation
  }
})
})
}

【问题讨论】:

    标签: javascript google-maps google-maps-markers infowindow


    【解决方案1】:

    让它工作......

    在底部我是这样做的:

    infowindow.open(map, this)
    

    用'marker'改变'this'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 2014-10-02
      • 2015-09-12
      • 2016-07-10
      • 2013-05-18
      相关资源
      最近更新 更多