2013-04-30 173 views
5

我有这个代码的问题,当我点击一个标记我想infowindow打开在那个标记的位置。谷歌地图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 
    } 
}) 
}) 
} 

回答

12

得到它的工作...

底部我这样做:

infowindow.open(map, this) 

改变 '这个' 与 '标记'

+1

谢谢你非常感谢:) – Preethy 2013-10-01 05:49:03