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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:52:50+00:00 2026-05-26T14:52:50+00:00

I need to catch the event of getting back suggestions for google maps autocomplete

  • 0

I need to catch the event of getting back suggestions for google maps autocomplete. I know it is undocumented, but doing some research I found that it could be down via some prototype hacking.

<input type='text' id='myInput'>
<script src="http://maps.google.com/maps/api/js?libraries=places&amp;sensor=false&amp;language=en-EN"></script>
<script>
function catcher(key) { console.log(key); }

function MyProto() {}
MyProto.prototype = new google.maps.MVCObject();
MyProto.prototype.changed = catcher;

var gAuto = new google.maps.places.Autocomplete(
    document.getElementById('myInput'), ['geocode']);

// one of two should be commented

//gAuto.__proto__.__proto__.changed = catcher; // every key, including 'predictions'

gAuto.__proto__.__proto__ = MyProto.prototype; // only 'types', '0', and 'place' when selected
</script>

JSFiddle link: http://jsfiddle.net/agentcooper/hRyTF/ (check the console)

Check the last two lines. When setting ‘changed’ function directly on MVCObject prototype (first one, commented), everything works great and I can catch key ‘predictions’ in the ‘catcher’ function. The problem is that catcher needs to be different if, for example, I need to have two instances of autocomplete on my page. So when I’m trying to inject custom object in autocomplete’s prototype chain (last line) everything fails. Is there any way to solve this?

EDIT: working version, thanks to Sajid 🙂

UPDATE: Completed the code, maybe it will be helpful to anyone

  • 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-26T14:52:51+00:00Added an answer on May 26, 2026 at 2:52 pm

    In the second line, you are replacing the entire prototype of the MVC object with an instance of the MVC object, and depending on how the thing is initialized, this will likely not work at all. The first like replaces one function, though in the process it completely breaks that function since you don’t call its superclass version, so you are not extending, you are really clobbering. To not clobber, you need to do:

    (function() {
        var oldChanged = gAuto.__proto__.__proto__.changed;
    
        function catcher(key) {
            // call old version, and make sure to maintain this reference correctly
            oldChanged.call(this, key);
            // do your stuff here
        }
    
        gAuto.__proto__.__proto__.changed = catcher;
    })();
    

    One simple solution is that each object has an idea of this mentioned above. So changed has a reference to this, which will refer to the object being used as the caller’s target (except in specific situations that are a bit out of scope here). But basically:

    var x = new MVCObject();
    x.changed('hi') // this === x
    

    So if your two versions need to do different things, you can check which this the changed method was called from and react appropriately.

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

Sidebar

Related Questions

I need to catch an event when the user presses the back key and
I need to catch the onTap event.Although i have onTap function but it opens
I need to catch that exception but I can't figure out which one it
I need to catch swipe-action only on special area. But debugger tells unrecognized selector
I need to write a delegate function that can 'wrap' some while/try/catch code around
I have never used Try-catch in my code before, but now I need to
I'm trying to catch event when comment is sent. What am I doing wrong?
I need to catch the event where the columns are resized. How do I
I need to catch key pressed event and prevent it's default behavior: launch iTunes
Is there any way I can catch the event when I press the back

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.