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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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