Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:10:13+00:00 2026-05-20T11:10:13+00:00

as part of my last.fm/google maps event mashup, I have to plot markers dynamically

  • 0

as part of my last.fm/google maps event mashup, I have to plot markers dynamically from last.fm API onto the google map.

This is all well but when I click the marker, only the last infowindow (for one gig) is displayed. I know the reasoning for this but struggle to implement it.

Currently I’m running a PHP loop through all the dynamic gig’s locations (co-ordinates) and then passing this to the javascript. This makes more sense to me – and my knowledge of PHP is much better than JS:

<?php 

            foreach ($gigs->events->event as $js_event) { 

            $lat = $js_event->venue->location->children("geo",true)->point->children("geo",true)->lat;
            $long = $js_event->venue->location->children("geo",true)->point->children("geo",true)->long;
            $coords = "$lat,$long"; 

            ?>      

            var image = new google.maps.MarkerImage('http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=G|00CC99|000000',
            new google.maps.Size(40, 32),
            // The origin for this image is 0,0.
            new google.maps.Point(0,0),
            // The anchor for this image is the base of the flagpole at 0,32.
            new google.maps.Point(0, 32));

                    var marker = new google.maps.Marker({

                      position: new google.maps.LatLng(<?php echo $coords ?>),
                      map: map,
                      icon:image, 
                      title: '<?php echo str_replace('\'','',$js_event->title) ." at ". str_replace('\'','',$js_event->venue->name) ?>'

                    });

                    var contentString = '<?php echo str_replace('\'','',$js_event->title) ." at ". str_replace('\'','',$js_event->venue->name)?>'

                    var infowindow = new google.maps.InfoWindow({
                        content: contentString
                    });

                    google.maps.event.addListener(marker, 'click', function() {
                      infowindow.open(map,marker);
                    });

                <? } ?>

How could I add closure without fully refactoring the loops to JS and not PHP, etc. Unless this is one of the only solutions?

Many, many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:10:14+00:00Added an answer on May 20, 2026 at 11:10 am

    An easy way to isolate the scope of your marker variable is to wrap the invocation in an anonymous function:

    var map = ...
    
    (function() {
        var image = ...
        var marker = ...
        ...
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map, marker);
        });
    })();
    

    As described here, the anonymous function will see anything in scope where it was declared. So inside the function can see map, which was in scope when it was declared. But outside the function, marker is invisible, so repeated clones of the anonymous function won’t impact each other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this question that talks about getting the last part of a
i need to filter my google maps markers. right now, i generate a map
Hopefully the last part of this menu I've been working on. It've got the
This is the last part of the program I am working on. I want
I really need help with this last part of my program. I need to
I am tying to retrive the last part of an path . I have
In my code I have to divs with different names, except the last part
I'm SOO close to finishing a pet project, this is the last part I
In this page: https://developers.google.com/appengine/docs/python/datastore/keyclass#Key_from_path This part: Key.from_path(kind, id_or_name, parent=none, namespace=None, **kwds) Builds a new
This is a script I have for a google spreadsheet. It all works except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.