javascript - 谷歌地图信息窗口位置

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

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

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

代码:

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
  }
})
})
}

最佳答案

开始工作了...

在底部我这样做了:

infowindow.open(map, this)

用“标记”改变了“这个”

关于javascript - 谷歌地图信息窗口位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16295228/

相关文章:

javascript - 禁用来自外部 Javascript 的表单操作字段

javascript - 在 Angular 分量中向谷歌地图添加标记

javascript - 如何使用页面 URL 提取多个产品页面的元标记?

javascript - 如何使用 Javascript 在 Google Map v3 中使用 GTFS feed?

ios - 如何在屏幕中央的 Google map 上查看驾驶员当前位置(驾驶时)?

google-maps - Google map 静态图像的最大网址长度

ios - 在 iOS 中获取谷歌地图中的可访问标记

javascript - 为什么 Netbeans 导航器 Pane 不使用特定文件名填充 javascript 文件?

javascript - 如何在 Google map 之外点击图钉上的位置详细信息

php - 使用 PHP 创建 Google map 标记