hamburgerlove413 Posted April 19, 2014 Share Posted April 19, 2014 Hello, I'm trying to send a variable that gets its text from an xml file to a markers information box, and I can't seem to get it to work. Can someone look at my code and tell me what I'm doing wrong? its the one marked "address" (line 52 and down). $(document).ready(function () { //google maps api $('#map_canvas').gmap({'zoom':3, 'center': new google.maps.LatLng(39.8282,-98.5795)}).bind('init', function(ev, map) { //last.fm api $( "#artistSearch" ).submit(function( event ) { $('#map_canvas').gmap('clear', 'markers'); //clear previous results $("#tourList h2").empty(); $("#artist").empty(); //name to send to API var artistName = $("#artistName").val(); //get API response $.get("http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=" + artistName + "&api_key=69d935120d26cbcbaeed4fac6f59dfb6", function(xml) { var resLength = $(xml).find("venue"); if (resLength.length != 0) { //attach heading $("#tourList").prepend("<h2>Tour List</h2>"); //find venues $(xml).find("venue").each( function() { title = $(this).find("name").text(); //build a list of the venues $("#artist").append("<li>" + title + "</li>"); }); } else { $("#artist").append("<li>No Results Found</li>"); } //grab lat and long $(xml).find("location").each( function() { geolat = $(this).find("geo\\:lat").text(); geolong = $(this).find("geo\\:long").text(); address = $(this).find("city").text(); $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(geolat,geolong) } ).click(function() { $('#map_canvas').gmap('openInfoWindow', { 'content': address }, this); }); //end of markers }); //end of locations }); event.preventDefault(); }); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/287880-passing-variable-to-google-maps-marker/ Share on other sites More sharing options...
mogosselin Posted April 21, 2014 Share Posted April 21, 2014 To know what doesn't work, did you try to output the value of "address" (before you add it to the "popup")? Is the value OK? Did you try to add any text in the map popup? Did it work? If not, maybe you should try with a simple empty map and just try to add a popup with a value in it. When you get how this work, you'll be able to add it to your program easily. P.S. I think you might want to remove your API key from your post... Quote Link to comment https://forums.phpfreaks.com/topic/287880-passing-variable-to-google-maps-marker/#findComment-1476863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.