Link to home
Create AccountLog in
Avatar of ALASKASTREETMASTER
ALASKASTREETMASTERFlag for United States of America

asked on

Google Markers

Hi, I am trying to set up list of markers in a div that will, when clicked on zoom to the marker and open the info popup. The routine works great and all markers and html links are created with the correct info.  However, whenever the link or the marker are clicked on they always refer to the first marker created.  Any help would be appreciated.

ii = globalmymarkers.length ;

marker[ii]  = new google.maps.Marker({

  position: myLatlng,
  icon:image,
  draggable: true,
  title:"Location - " + datarec[68] + " - " + datarec[59],
  letter: letter,
  contents: getgrid + getdispatch + getdetail + gethistory

  });

marker[ii].infowindow = new google.maps.InfoWindow({content:getgrid + getdispatch + getdetail + gethistory });
marker[ii].infowindow.close();

google.maps.event.addListener(marker[ii], "click", function () {marker[ii].infowindow.open(globalmap, marker[ii])});

globalmymarkers.push(marker[ii]);
mgr.addMarker(marker[ii], 0);
mgr.refresh();

google.maps.event.addListener(marker[ii], 'dblclick', function() {mgr.removeMarker(marker[ii]); updateStatus(mgr.getMarkerCount(globalmap.getZoom()));});

globalmyhtml += '<b>'+letter+'&nbsp&nbsp<\/b>' + '<a href="javascript:myclick(' + (globalmymarkers.length-1) + ')">'+ datarec[68] + ' - ' + datarec[59] + '<\/a><br>' ;
document.getElementById('maploc').innerHTML = globalmyhtml;

// function to view marker  info window.
 function myclick(ii) {
       google.maps.event.trigger(globalmymarkers[ii], 'click');
     
}
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

That can't work because there is no loop to change the value of 'ii'.  Check the code on this page.  It shows how to create the markers and the info that appears when you click on it.  https://developers.google.com/maps/articles/phpsqlsearch_v3
Avatar of ALASKASTREETMASTER

ASKER

The code above is in a routine that is called each time my query to the data base is called. Once a location is selected from the query it calls the  setmap routine which the above code is in.  ii is changed by getting the length of the globalmymarkers array and setting ii to that.  I am using xajax to query the database. The globalmymarkers array is not reset when the query is performed.

The globalmymarkers array does contain all the markers that are added. I tested the routine, and through an alert viewed the ii value.  It increments each time I do a query. The values in the html link are also incremented when calling the myclick function in the link.  ii is being sent correctly from the html link to the myclick function . I checked the values of the globalmyhtml variable and it correctly contains a different value for each link.

The attached image show the html links.
html.png
site is at 66.29.204.172

a couple of test addresses:

5615 Naknek Ln
4105 Turnagain Blvd

paste the address in the search box on the left, wait a second and it will populate.  Click on an item in the results list. Click OK on the pop up and then do the same with the second address.

The HTML links show up on the top right. Both links go to the same marker.
The links in the upper right don't go anywhere in Firefox.
another problem....  try IE
Apparently your 'myclick' routine can't distinguish between '0' and '1'.  The advantage of Firefox is that I can see all the CSS and style errors on your page.  Also, '</br>' is not a valid tag, it should be '<br>' or '<br />'.
I wrote this entire site in a text editor.  I will can change the </br> Thanks.

I tried making sure the ii in the myclick function was a number. didn't work.
Any suggestions.
I tried in the my click function:

  google.maps.event.trigger(globalmymarkers[ii], 'click');
  google.maps.event.trigger(globalmymarkers[0], 'click');
  google.maps.event.trigger(globalmymarkers[1], 'click');

they all give the same first record. no error.

This is a google api function. Maybe it cannot read from an array?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
got it working, needed to put the calls to the marker in a formatted div.
Thanks for your help!
Good!  Thanks for the points.