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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:34:28+00:00 2026-05-25T06:34:28+00:00

Hey I’m fooling around with google maps API, and at the moment I am

  • 0

Hey I’m fooling around with google maps API, and at the moment I am struggling to implement something that I would think would be fairly straight forward.

My friend wants to have one of those visitor map things on his site where visitors can add a marker to any point on the map, and with each marker there will be information associated with it. Information such as name, date, message, etc….

Right now I am in the prototyping and learning stage, but I am having trouble associating an infowindow with a marker object.

var map;
var markers = []
function init(){
        var latlng = new google.maps.LatLng(-44, 140);
        var myOptions = {
                zoom:8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


        google.maps.event.addListener(map, 'click', function(event){
            markers.push(new marker(event.latLng));
        });
}

function marker(location){
    this.location = location;
    this.mark = new google.maps.Marker({position:this.location, map:map});
    this.info = new google.maps.InfoWindow({content:'hi'});
    google.maps.event.addListener(this.mark, 'click', function(){
        this.info.open(map, this.mark);
    });
}

When I test this code out the markers are placed fine, but when I click on them, instead of displaying the InfoWindow I get this error in the JS console:

Uncaught TypeError: Cannot call method 'open' of undefined

Certainly this is a scope problem, but I can’t understand why that should be. Something like this works fine:

function test(a){
    this.a = a
    this.b = function(){
        this.a+=1
    }
}

Thanks a lot for the help!

  • 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-25T06:34:29+00:00Added an answer on May 25, 2026 at 6:34 am

    Looks like you’re losing scope here:

    google.maps.event.addListener(this.mark, 'click', function(){
      this.info.open(map, this.mark);
    });
    

    Try storing the value of this like so:

    var _self = this;    
    google.maps.event.addListener(_self.mark, 'click', function(){
      _self.info.open(map, _self.mark);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I'm building an app that will allow a user to log into a
Hey so I've been searching around for this topic and couldn't find a whole
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey everyone I am a newbie and would love some help. I got the
Hey guys I have my script here that is supposed to do some stuff
Hey guys I'm tired and can't figure this one out so any help would
Hey all i have an XML file that i am trying to loop though.
Hey guys I am struggling to create a query which gives schedule of a
hey i got a contnet type that i made and i want to twweak

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.