somethings from codeland

Friday, October 27, 2006

more on google maps

So I decided to do this instead of making a doc on my google account..

Here we go:

GMap2 api reference

every time a new instance of GMap2 is created another map is displayed on the screen.

So everything starts with:
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
GEvent.addListener(map, "click", function() {
alert("You clicked the map.");
});


this will show a popup screen that says "You clicked the map." every time the user clicks the map.

you can add listeners (as demonstrated above) or bind them:

function MyApplication() {
this.counter = 0;
this.map = new GMap2(document.getElementById("map"));
this.map.setCenter(new GLatLng(37.4419, -122.1419), 13);
GEvent.bind(this.map, "click", this, this.onMapClick);
}

MyApplication.prototype.onMapClick = function() {
this.counter++;
alert("You have clicked the map " + this.counter + " " +
(this.counter == 1 ?"time" : "times"));
}

var application = new MyApplication();


onMapClick is a method that is bound to the event listener for this particular map (this particular instance of GMap2)

No comments:

Twitter Updates

About Me

My photo
I have been working with computers/programming to put myself through college since I graduated high school. I am currently attending Oklahoma State University for bachelors degree in biological sciences. Along with my experience in programming, a degree in biology will allow me to pursue a career in bioinformatics research concerning genetic diseases (i.e. cancer).

Blog Archive