google maps api … showing a markers infowindow from a link outside of the map

前端 未结 1 1806
不知归路
不知归路 2020-12-11 06:01

I\'m trying to build an interactive map using google\'s map api v3. The idea is to populate a list of markers on the map with some text using asp.

Creating the map,

1条回答
  •  悲哀的现实
    2020-12-11 06:55

    You need to store your markers in an array that can be used later. Right now the code

    markerID = this.id;
    

    Is just going to be set to "marker1", it isn't actually the marker object. You need to create a collection of markers:

    var markers = new Array();
    

    After you create a marker you need to store it in the array:

    markers.push(marker);
    

    When your

  • element receives a click event you need to retrieve the marker from the array of markers:

    marker = markers[this.id]; 
    

    Here is a working example:

    
    
    
    
    
    
    
    
    • Salt Lake City
      Capital of Utah
      40.763901
      -111.901245
    • Provo
      Location of BYU
      40.25228
      -111.659546

0 讨论(0)
提交回复
热议问题