Should be simple... markers not appearing.

21 views
Skip to first unread message

Jo

unread,
Jun 16, 2011, 11:29:45 AM6/16/11
to google-map...@googlegroups.com
So I have a map that appears... And I'm trying to add an even listener that will create a marker when the user clicks a spot on the map. here's my js code for initializing my map and adding a marker...
I know that the code reaches the creation of the marker... just nothing happens! Help please!


bn.Curiosity.initialize = function () {
    var myLatlng = new google.maps.LatLng(54.397, -106.644);

    var map = new google.maps.Map(document.getElementById("map_canvas"), {
        zoom: 4,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    google.maps.event.addListener(map, 'click', function (event) {
        
        var marker = new google.maps.Marker({
            
            position: event.latlng,
            map: map,
            visible: true,
            clickable: false,
            title: 'hello world'
        });
        map.setCenter(location);


    });
}

Cornelius Parkin

unread,
Jun 16, 2011, 2:52:43 PM6/16/11
to google-map...@googlegroups.com
Hi

The most obvious thing I can see is that "location" is not set. It should be a latlong object.

Regards
CAP

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/Zzg-wnlgU-cJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.



--
Warm Regards

C.A.Parkin

~"When you innovate, you've got to be prepared for everyone telling you you're nuts" - Larry Ellison~

en4ce

unread,
Jun 16, 2011, 3:03:29 PM6/16/11
to Google Maps JavaScript API v3
the location is set, but you need a array to store the marker

try something like this:
var markers = [];
bn.Curiosity.initialize = function () {
[code]
google.maps.event.addListener(map, 'click', function (event) {

var marker = new google.maps.Marker({
position: event.latlng,
map: map,
visible: true,
clickable: false,
title: 'hello world'
});
markers.push(marker);
map.setCenter(location);

});

this should do the trick

On 16 Jun., 20:52, Cornelius Parkin <cornelius.par...@gmail.com>
wrote:
> *~"When you innovate, you've got to be prepared for everyone telling you
> you're nuts" - Larry Ellison~*

Rossko

unread,
Jun 16, 2011, 3:42:34 PM6/16/11
to Google Maps JavaScript API v3
> the location is set, but you need a array to store the marker

I'm not sure what difference that would make??

Me, I'm wondering if 'map' is in scope at the time of the click event,
I think not.

Oh, if only we could see the webpage so we could debug in context
instead of guessing.

Andrew Leach

unread,
Jun 16, 2011, 3:52:50 PM6/16/11
to google-map...@googlegroups.com
On 16 June 2011 20:42, Rossko <ros...@culzean.clara.co.uk> wrote:
>
> Me, I'm wondering if 'map' is in scope at the time of the click event,
> I think not.

That's what occurred to me, too. There may be a variable called "map"
in scope. However, it won't be the variable holding the map.

> Oh, if only we could see the webpage so we could debug in context
> instead of guessing.

Quite. Despite the posting guidelines in a sticky post, I've lost
count of the number of times this comment is made. (NB: "See the
webpage" doesn't mean "see a code listing")

geoco...@gmail.com

unread,
Jun 16, 2011, 3:30:15 PM6/16/11
to Google Maps JavaScript API v3
On Jun 16, 12:03 pm, en4ce <djen...@googlemail.com> wrote:
> the location is set, but you need a array to store the marker

You don't need an array to store the marker unless you are going to
use it for something.

I would suggest the original poster check for javascript errors and
fix them. I don't see anything obvious, but as they didn't provide a
link (as requested in the posting guidelines) I can't tell what is
going on.

-- Larry
Reply all
Reply to author
Forward
0 new messages