2013-04-30 14 views
5

Ho un problema con questo codice, quando clicco su un marcatore voglio che l'infowindow si apra nella posizione di quel marcatore.Google Maps Posizione a valle

Quando faccio clic su ogni indicatore, si aprono tutti nella stessa posizione.

codice:

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

risposta

12

preso a lavorare ...

in fondo ho fatto questo:

infowindow.open(map, this) 

cambiato 'questo' con 'marker'

+1

ringraziamento tu molto :) – Preethy

Problemi correlati