ALASKASTREETMASTER
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({co ntent:getg rid + getdispatch + getdetail + gethistory });
marker[ii].infowindow.clos e();
google.maps.event.addListe ner(marker [ii], "click", function () {marker[ii].infowindow.ope n(globalma p, marker[ii])});
globalmymarkers.push(marke r[ii]);
mgr.addMarker(marker[ii], 0);
mgr.refresh();
google.maps.event.addListe ner(marker [ii], 'dblclick', function() {mgr.removeMarker(marker[i i]); updateStatus(mgr.getMarker Count(glob almap.getZ oom()));}) ;
globalmyhtml += '<b>'+letter+'  <\ /b>' + '<a href="javascript:myclick(' + (globalmymarkers.length-1) + ')">'+ datarec[68] + ' - ' + datarec[59] + '<\/a><br>' ;
document.getElementById('m aploc').in nerHTML = globalmyhtml;
// function to view marker info window.
function myclick(ii) {
google.maps.event.trigger( globalmyma rkers[ii], 'click');
}
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({co
marker[ii].infowindow.clos
google.maps.event.addListe
globalmymarkers.push(marke
mgr.addMarker(marker[ii], 0);
mgr.refresh();
google.maps.event.addListe
globalmyhtml += '<b>'+letter+'  <\
document.getElementById('m
// function to view marker info window.
function myclick(ii) {
google.maps.event.trigger(
}
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
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
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
ASKER
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.
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.
ASKER
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 />'.
ASKER
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 making sure the ii in the myclick function was a number. didn't work.
Any suggestions.
ASKER
I tried in the my click function:
google.maps.event.trigger( globalmyma rkers[ii], 'click');
google.maps.event.trigger( globalmyma rkers[0], 'click');
google.maps.event.trigger( globalmyma rkers[1], 'click');
they all give the same first record. no error.
This is a google api function. Maybe it cannot read from an array?
google.maps.event.trigger(
google.maps.event.trigger(
google.maps.event.trigger(
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
got it working, needed to put the calls to the marker in a formatted div.
Thanks for your help!
Thanks for your help!
Good! Thanks for the points.