I am trying to use the Google Maps API to get the location provided by the user. To do this, I set a marker that moves based on click events. Code as such:
function initialize_google_map(div_id) {
var map = new GMap2(document.getElementById(div_id));
map.setCenter(new GLatLng(45, -105), 2);
map.setUIToDefault();
return map;
}
$(document).ready(function() {
var map = initialize_google_map("map_canvas");
var marker = google.maps.Marker({map: map, title:"Location"});
google.maps.event.addListener(map, "click", function(evt) {
alert("got click event");
marker.setPosition(evt.latLng);
});
$(document).unload(function() {
GUnload();
});
});
The warning "received click event" never fires, and my Javascript console (Google Chrome) says the following:
Uncaught TypeError: Unable to call 'addListener' method from undefined
The API is included something like this:
<script src="http://maps.google.com/maps?file=api&v=3&sensor=true" type="text/javascript"></script>
source
share