> I tried a lot of things but I can't get it working. I'm not understanding
> how to add a listner to the map.
What you have to add the listener is fine ; but it can't find the
'map' to attach to.
You have declared an empty variable 'map' in the global scope at line
75
var map;
but inside your function load() you have
var map = new google.maps.Map( ...
which creates a new local variable called 'map' to hold your map
object. When your load() function has completed, that local 'map'
will not be available.
When the user clicks the place-marker button, your placeMarker()
function calls
google.maps.event.addListener(map ...
but that will fail as it tries to use the global 'map' which is still
empty.
Change the line inside load() to
map = new google.maps.Map( ...
to create your map object in the global 'map', where it will be
available later on.
----
The next problem you will run into is that you have declared your
function addMarker() inside the declaration for placeMarker().
function placeMarker() {
...
function addMarker(latLng){
....
}
}
This means that addMarker will be local, inside placeMarker, and
when placeMarker has finished dealing with the button click, addMarker
will not be available anymore. It will not be there when the user
clicks on the map to actually place the marker. Move the declaration
outside
function placeMarker() {
...
}
function addMarker(latLng){
....
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.