1

After looking at the suggested sites in the spec, I wrote the code for the addMarker function, and no matter what I can't get the markers to show up on the map in mashup. To me, the code looks 100% correct, but I think I need some additional eyes to see if I missed something. Code is below:

function addMarker(place)
{
    function initialize() {

        markers = place; 
        var myLatlng = new google.maps.LatLng(parseFloat(markers.latitude), parseFloat(markers.longitude));

        var marker = new MarkerWithLabel({
           position: myLatlng,
           map: map,
           labelClass: "labels",
           labelContent: markers.place_name,
           labelAnchor: new google.maps.Point(20,0),    
        });
    }

    google.maps.event.addDomListener(window, "load", initialize);


}

1 Answer 1

1

addMarker is called when then map already exists and it's called in a loop to add multiple markers. I believe your code is setup to add one marker on load of the map.

rather than having a embedded function initialize and using a .addDomListener, you need to place as a market and then .addListener with the marker and "click" as the event.

Also, markers is defined in scripts.js:

// markers for map
var markers = [];

I'm not sure, if I could even understand my own instructions, so I will just modify your code above that should make it work:

function addMarker(place)
{

    var myLatlng = new google.maps.LatLng(parseFloat(markers.latitude), parseFloat(markers.longitude));

    var marker = new MarkerWithLabel({
           position: myLatlng,
           map: map,
           // you might want to define your own icon with icon:PATHTOIMG;
           labelClass: "labels",
           labelContent: place.place_name,
           labelAnchor: new google.maps.Point(20,0),    
        });

    google.maps.event.addListener(marker, "click", function()  {xxx(marker, place.postal_code);} );

 // last you need to add marker to markers []
 // TODO

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .