appActions.updateDataSlot not working

Hello all. Hope this finds a solution from someone. I’m integrating Google Maps Platform with RS, and so far I’m doing good. That was 3 days ago when I started to face a problem when updating a data slot with the coordinates I have. As you can see in the print (console).


I thought this would be very simple, but for some reason I’m not getting there. So, what I get if I leave the RS “appActions.updateDataSlot” line not commented is an error “Uncaught TypeError: Cannot read property ‘appActions’ of undefined” ?!

Here’s the script that works fine without the “appActions.updateDataSlot” line.
Just to get in touch with this GM API. This is a listener that gets the latitude and longitude after dragging a marker on the map.
//
google.maps.event.addListener(marker, ‘dragend’, function (event) {
//do something
let markerLat = this.getPosition().lat();
let markerLon = this.getPosition().lng();
console.log(markerLat,markerLon);

            //this.props.appActions.updateDataSlot('ds_SlotLat', markerLat)
       })

I appreciate your help

I couldn’t wait:) here’s what you should do: use Web Storage API just like React Studio does.
So instead of:
// this.props.appActions.updateDataSlot(‘ds_SlotLat’, markerLat)
do the same using to update your data slots :
localStorage.setItem(“ds_SlotLat”, markerLat);
localStorage.setItem(“ds_SlotLon”, markerLon);

have fun

The problem is probably with the listener function definition/syntax. ‘this’ inside the function references something else than the containing component (probably a marker). One option to solve it is to do something like this:

let appActions = this.props.appActions;
google.maps.event.addListener(marker, ‘dragend’, function (event) {
  ....
  appActions.updateDataSlot('ds_SlotLat', markerLat);
});
1 Like

Hey Juha. I truly appreciate your help. You rock.
On the other hand, these days were great to learn how to deal with storage… :slight_smile:
By the way, to get item() simple use localStorage.getItem(‘storage_item’)

2 Likes