簡體   English   中英

Google Maps Infowindow職位

[英]Google Maps Infowindow Position

我有這個代碼的問題,當我點擊一個標記我希望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)

用'標記'改變'this'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM