Solved

Referencing Google Maps API markers from Javascript

Posted on 2013-06-17
2
407 Views
Last Modified: 2013-06-17
Here is my test page:
http://tech.lifespanfitness.com/store-locator.asp?p=19565

It works fine. If you click any of the red markers on the map, you get a details "info window". The click event is coded like this:

google.maps.event.addListener(marker0,'click', function(){
	infowindow.close();
	infowindow.setContent('<p><b>Play It Again Sports - Wyomissing</b><br />1050 Berkshire Blvd, Wyomissing, PA 19610<br />United States<br />610.779.8360<br />Distance: 5 miles or 9 kilometers</p>');
	infowindow.open(map,marker0);
});

Open in new window


However, I would like to also trigger these "info window" events from other elements. For example, I setup a test button on that same page (you will see it at the top-right of the screen):

<input id="mybutton" type="button" value="click here" />

Open in new window


I tried handling that button like this:

$(function(){
	$('#mybutton').click(function(marker0){
		infowindow.close();
		infowindow.setContent('content here');
		infowindow.open(map,marker0);
	});
});

Open in new window


...but I just get an error "cannot find the variable 'infowindow'".

How can I make it so clicking that button displays one of the five info windows on that screen? I guess I am not sure how to reference the info window, outside of the code that Google Maps API has already provided.

Thank you!
0
Comment
Question by:bbdesign
2 Comments
 
LVL 4

Accepted Solution

by:
Ersoy Hasan earned 500 total points
Comment Utility
You can't find infowindow variable because it is defined inside the initialize function's scope and you are trying to access it outside it. Move this :
		$('#mybutton').click(function(marker0){
			infowindow.close();
			infowindow.setContent('content here');
			infowindow.open(map,marker0);
		});

Open in new window

inside the initialize function.
0
 

Author Comment

by:bbdesign
Comment Utility
You are correct, that fixed it. Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now