Jump to content

passing variable to google maps marker


hamburgerlove413

Recommended Posts

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

		
});


});

Link to comment
https://forums.phpfreaks.com/topic/287880-passing-variable-to-google-maps-marker/
Share on other sites

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.