javascript - How to call a object defined function from the a different function in the same object? -


I am creating a custom object with javascript for small personal projects, which is used mostly with the tablet (but As well as laptops too). Object is defined as Google Maps, GPS tracking, along with other processes, within the object I have defined some functions from outside the object ( enableGps, disableGps ). To handle GPS data (latitude, longitude, accuracy, etc.) inside enableGps, I start tracking error handler and when using the object function inside ( this.handleGps ). In this.handleGps, I try to call the this.updateGpsMarker function to update the actual marker on the map, but the exception is thrown.

UnkeyType Error: There is no way 'updateGpsMarker' in Object [Object Window]

I this.updateGpsMarker How do I call this.handleGps ? Please note that I need to be available as a function to call this.updateGpsMarker outside (long description), I will remove the code to make it more clear which I I am trying to Function Root Assistant (Map Cavan, Map Option) {// Google Mapping and GeoCoding this.map = New google.maps.Map (map, sheeting, map options); This.geo = new google.maps.Geocoder (); This.gpsMarker = Null; This.updateGpsMarker = function (latitude, LAN) {console.log ("updating GPS marker"); If (this.gpsMarker == null) {console.log ("GPS marker has not been created". + + Latitude + +, "GPS" marker on "+ Loan"); This gpsMarker = new google.maps.marker ({status: new google.maps.LatLng (latitude, lan), map: this.map, title: "I am here!"}); This.map.setCenter (new google.maps.LatLng (lat, lon)); } Else {console.log ("GPS Marker was created, updating" + Latitude + "," + Loan "to GPS Marker); This.gpsMarker.setPosition (new google.maps.LatLng (latitude, lan)); }} // GPS and tracking this.gpsProcess = tap; this.enableGps = function (handle_errors) {if (this.gpsProcess == faucet) {console.log ("GPS to enable"); This.gpsProcess = Navigator .jolocation.vache (this handloads GPS, handlers);}} This.disableGps = function () {if (this.gpsProcess! = Null) {console.log ("disable GPS"); navigator.geolocation.clearWatch (This.gpsProcess); This.gpsProcess = null;}}; This.handleGps = car (Status) {this.updateGpsMarker (position.coords.latitude, position.coords.longitude); Perhaps you can make a clear object such as some revealing modulo patterns and.

  var route assistant = Functions (map canvas, map options) {var map = new google.maps.Map (mapCanvas, mapOptions) all your functions. UpdateGpsMarker = function (lat, long) {// You can directly use 'map' Here you can }; Return {updateGpsMarker: updateGpsMarker}; };   

Then you can use it by

  var myObject = new routeAssistant (mapCanvas, mapOptions); MyObject.updateGpsMarker (latitude, longitude);    

Comments