1

I am trying to create a wrapper for google map api. The following function is part of an object. I keep getting "self is undefined". Typically the listener only has function(event), I tried adding self to the parameter list to get access to the parent object.

var self = this;

google.maps.event.addListener(this.geoMarker, 'dragend', function( event, self ){

      //update input 
      self.lat = event.latLng.lat(); //ERROR: self is undefined
      self.lng = event.latLng.lng();


      //udpate any fields that were set
      self.updateDisplay();  

      self.geoMarker.setTitle("Lat: " + event.latLng.lat() + '   Lng: ' + event.latLng.lat() );

}); 

2 Answers 2

3

You should remove the declaration of self from the callback's parameter list - it's over-riding the external declaration.

Sign up to request clarification or add additional context in comments.

1 Comment

perfect thanks, you'll get the check after the waiting period ends.
0

Remove the second parameter (self) from the callback function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.