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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:49:31+00:00 2026-06-03T15:49:31+00:00

I have a view that contains a google map accessible via this.map within the

  • 0

I have a view that contains a google map accessible via this.map within the view scope. All is well in the world.

Next I want to update the map position via events in my view. To do this I take text input, use google.maps.Geocoder.geocode(), then update the position via:

setMapLocation: function (location) {

    _.bind(this.setMapLocationCallback, this);

    console.log(this);

    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({'address': location}, this.setMapLocationCallback);

},

The console.log(this) here shows me the scope of the view, with this.map properly accessible. Notice that I explicitly bind the callback to this here. Here’s the callback:

setMapLocationCallback: function (results, status) {

    console.log('this in the callback');
    console.log(this);

    if (status == google.maps.GeocoderStatus.OK) {
        this.map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: this.map,
            position: results[0].geometry.location
        });
        this.mapCanvas.css({visibility: 'visibile'});
    } else {
        this.mapCanvas.css({visibility: 'hidden'});
    }
},

The problems is that inside the callback console.log(this) shows that this is scoped to the Window object even though I bound it explicitly to the view object’s this scope.

I need to access this.map in the callback because I may have more than one map on a page and need to distinguish which one I’m talking about.

How do I bind this callback to the proper scope? or, is there a better way to do this?

I’m using backbonejs and underscorejs, but this should be a fairly generic problem.

Thanks in advance,
David

  • 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-03T15:49:33+00:00Added an answer on June 3, 2026 at 3:49 pm

    try changing

     geocoder.geocode({'address': location}, this.setMapLocationCallback);
    

    using call(), so you can change the scope of this inside setMapLocationCallback

     var _this = this;
     geocoder.geocode({'address': location}, function(result, status) {
         _this.setMapLocationCallback.call(_this, result, status);
     });
    

    MDN Documentation about call() function

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

Sidebar

Related Questions

I have a hypothetical tree view that contains this data: RootNode Leaf vein SecondRoot
I have my view that contains the UIPickerView... I tried to make this code:
Hi, I have a View class that contains a list, this list explains the
I have a view that contains nested views of the same type. Because of
I have a view that contains two NSTextFieldCell s. The size at which these
I have a view model that contains a Product class type and an IEnumerable<
I'm developing an iOS 4 application. I have a main view that contains another
I have developed a small view that contains special char like 'é' and when
I have an ASP.NET MVC view that contains a lot of similar code and
I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured

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.