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 7720665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:43:57+00:00 2026-06-01T03:43:57+00:00

Problem: I want to put Twitter Share Button in my Google Map InfoWindow. I

  • 0

Problem: I want to put Twitter Share Button in my Google Map InfoWindow.

I have used a google.maps.event.addListener(infowindow, ‘domready’ function() { …code…} to listen for the InfoWindow to be added to the DOM but it only works on the first InfoWindow launched.

The Twitter Share Button Examples apply the following script:

!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

against the class:

"twitter-share-button"

Assumption:
Now the problem as I see it is that the InfoWindow and markers get created in the $.each() loop and I don’t know what event to get jQuery to watch for.

I have tried creating a jsfiddle as an example but I can’t get it to load the map if I use $.each() like in the live site but I link it here in case it helps you demonstrate an answer:

My non-working JSFiddle.

My live development site which shows the problem.

Other Stack Overflow questions: Similar but different.

Calling a JavaScript function within an InfoWindow (Google Maps)

Tweet button and infoWindow

I’ve seen the jQuery-ui-map plugin. That doesn’t do anything I can’t do in straight JavaScript.

Map.js: or Pastebin link to code below but with syntax highlighting

$('.page-map').live("pageshow", function() {

    $.getJSON("/rest/Pub", function(data) {

        var latlng = new google.maps.LatLng(59.920, 10.750);  
        var map = new google.maps.Map(document.getElementById("map-canvas"), {
                // zoom is good on iphone @ 13 but better on desktop @ 14
                zoom: 12,
                center: latlng,
                backgroundColor: 'black',
                mapTypeControlOptions: { 
                    style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
                },
                mapTypeId: google.maps.MapTypeId.HYBRID
        }); 
        var bubble = new google.maps.InfoWindow();
        var pubs = data.list.Pub;

        $.each(pubs, function(i, pub) {

            var beer;
            var pubaddress = encodeURI(pub.pub_address);
            var pubname = encodeURI(pub.pub_name);
            var posi = new google.maps.LatLng(pub.pub_lat, pub.pub_long);
            var marker = new google.maps.Marker({
                animation: (pub.pub_bounce =='true') ? google.maps.Animation.BOUNCE : null,
                map: map,
                icon: "/static/images/" + pub.beer_price + ".png",
                shadow: 'static/images/shadow.png',
                position: posi,
                title: pub.pub_name
            });

            if (pub.beer_price == 99) {
                marker.setZIndex(1);
            } else {
                marker.setZIndex(100);
            }

            google.maps.event.addListener(marker, 'click', function() {
                // http://mapki.com/wiki/Google_Map_Parameters
                    if (pub.beer_price == 99) {
                        beer = '?';
                    } else {
                        beer = pub.beer_price; 
                    }

                tweet = '<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://oslogigs.com" data-text="' + pub.pub_name + '" data-lang="en" data-via="OsloGigs" data-hashtags="oslo, oslogigs, norway">Tweet</a>';

                content_string = '<h1>'+  pub.pub_name + '</h1>'+
                '<p><a href="http://maps.google.com/?saddr=Current%20Location&daddr=' + 
                pubaddress + '+(' + pubname + ')&dirflg=w&t=h">Google Maps Directions</a></p>' +
                '<p>Phone:<a href="tel:' + pub.pub_phone + '">' + pub.pub_phone + '</a></p>' +
                '<p>Halvliterpris: NOK <b>' + beer + '</b></p><p>' + tweet + '</p>';


            bubble.setContent(content_string);
            console.log(bubble.getContent());
            bubble.open(map, this);
            });

            google.maps.event.addListener(bubble, 'domready', function() {
            //$('.twitter-share-button').on('domready', function(event) {
               console.log("Iteration:"+ i + " Twitter javascript loaded " + pub.pub_name);
               !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
            });
        });
    });
});

Cheers.

  • 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-06-01T03:43:58+00:00Added an answer on June 1, 2026 at 3:43 am

    Calling

    twttr.widgets.load();
    

    after

    bubble.open(map, this);
    

    should do the trick.

    Since you’re loading the twitter widgets JavaScript asynchronously, you might want to check if twttr is already defined, before calling it.

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

Sidebar

Related Questions

I have a problem with HashMap. I want to put into map: key -
I'm experiencing this problem: I want to add the Google Maps API to my
I have a problem with my custom tableview cell. When I want to put
My problem is I have paths to draw cities and I want to put
The Problem I want to press a key when I have a line highlighted
I have a problem I want to know your opinion. I am trying to
I have a UIWebView which I want to put under my translucent UINavigationBar. Normally
I'd like an advice to the following problem: I want to embed a Button
I have an ADT (PCB aka Process Control Block), I want to put them
Using the Zend Framework , I have a menu and want to put it

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.