Skip Navigation

[Resolved] Strange behaviour of toolset-maps-distance-value on mobile

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 14 replies, has 3 voices.

Last updated by patrickF-7 1 year, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2511139

Tell us what you are trying to do? I created several views displaying list of CPT (ex. restaurants) with for each CPT the corresponding distance from the user (mobile position). I've a very strange behaviour. The first time (just after the login and after having autorised the mobile localization), the view displays the "dummy" distance (parameter message_when_missing). After 1 sec, the page is refreshed with the distances. But sometimes, the page is never refreshed, and the distance stay at the default message. Once a single view work, all do and the have the distance from the start (no refresh). Can you explain me how it works and how to ensure a consistent behaviour ?

Is there any documentation that you are following? The one provided online, I checked all related posts on the forum, but no one else mentioned this issue.

Is there a similar example that we can see?

What is the link to your site?

#2511523

Hello,

The distance feature of Toolset Maps plugin need to:
1) Ask for permission to get user's location
2) Get the user's location,
3) Use the location value to calculate distance results.
In order to get user's location, by default it needs to ask for permission first:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-geolocation
So it is expected result:
After 1 sec, the page is refreshed with the distances

For the issue: But sometimes, the page is never refreshed
But sometimes, the page is never refreshed, and the distance stay at the default message
This is abnormal, please check if there is any JS errors in your website.

#2511731

Hi Luo,. In order to simplify my tests and identify the issue, I added :
[wpv-geolocation message_when_missing="--------------"] [/wpv-geolocation]
at the beginning of my mobile home page. And to debug, in the page I use the JS "navigator.permissions.query({name:'geolocation'}) ..." to know if the geolocalization is granted or not.

And actually sometimes the geolocalization is granted but I still see the "--------------" (message when missing). And I can refresh the page, it doesn't change. However if I go to the other pages requiring as well the geolocalization, whenever 1 work, all later work (including the home page).

I managed to reproduce the issue on chrome simulating a mobile(Pixel 5). I see nothing in the console and no errors on WP side.
Do you know how I could investigate further the issue ?

#2512155

Please get the JS debug logs from your Pixel 5 device. See google document:
hidden link

#2512189

Actually I was not clear in my previous message. I reproduced the issue on PC in Chrome by simulating a mobile access (you can set chrome in debug (F12) and ask it to behave like a phone (ex. Pixel 5). And in the console there is no error.

#2512331

By investigating further with Chrome (in mobile mode) it seems that the bug occurs when the browser cache is activated. When deactivated the problem never happen.

#2514595

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo is on vacation. This is Minesh here and let me step in and I'll try my best to help you further.

I would like to know on what page/post you experience the issue. Are you using any cache plugin? if yes, what if you disable that and check again.

In addition to that - what if you disable the view cache, I'm not sure yet if you are using classic view or block view. Do you experience the same with any other browser?

#2514849

Hi Minesh. Thanks. I'm really struggling with this distance calculation issue. No I don't use any cache mecanism / plugin. What is really weird is that the Toolset code ment to figure-out the position / localization seems to work only from time to time, on some phones and not on others. I'm referring to this code :

<script id='toolset-maps-location-js-after'>
jQuery( function() {
jQuery( window ).on( 'load', function() {
WPViews.location.initWithReload();
} );
} );
</script>

added to ther page by toolset-maps-geolocation-shortcode.php. From time to time the page reload correctly, and sometimes not ...

#2514875

And BTW I've an additional question. The script toolset_maps_location.js figures out the localization either from a cookie (1st option) or from the phone localization (if 1st option failed). My question is: does the toolset view update the user position when the view is refreshed of does it keep a fix position (the one stored in the cookie) ? As with the second option, when the user move (walking or by car), the distance will be taken from an old / fix position position ...

#2515121

I maybe identified the issue of the erratic behaviour. Your code (copied above) is not activated when the "load" event is triggered before the "ready state" one (as discuscussed in this thread : hidden link). I modified the code in order to keep the activation on the "ready state" event only, and it seems to work:

$js = <<<JS
jQuery( function() {
WPViews.location.initWithReload();
} );
JS;

Do you know why it's required to have the two nested ?

#2515153

Would this code fix the issue in order to call the initWithReload whatever event comes first between ready and load ?

var toolsetWindowLoaded = false;
var toolsetDocReady = false;

jQuery( function() {
if(toolsetWindowLoaded && !toolsetDocReady) WPViews.location.initWithReload();
toolsetDocReady = true;
});

jQuery( window ).on( 'load', function() {
if(toolsetDocReady && !toolsetWindowLoaded) WPViews.location.initWithReload();
toolsetWindowLoaded = true;
});

#2515157

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

jQuery may change over time and that is the result there is another report is added which you already shared:
- hidden link

I suggest you should try to use ready method for now and check if that works for you otherwise the workaround you just shared with the previous reply. I'm keeping a note of this and will report it to concern department. Please note that there is no ETA on when official fix will be offered that is why I suggest for now to take a note of this and use the workaround that best suits your needs and works for you.

#2515195

OK Minesh, thanks. The problem is that my fix is a change to the Toolset code, meaning that each time Toolset is updated, the update will likely overwrite my fix (I'll have to cope with that).

Could you please answer to my other question: is the localization calculated on a regular basis or only once, stored in a cookie and reused for all calls ? I ask as my application on mobile is ment to provide the distance of interesting locations but the distance should be up to date with the user position over time.

#2515229

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

OK Minesh, thanks. The problem is that my fix is a change to the Toolset code, meaning that each time Toolset is updated, the update will likely overwrite my fix (I'll have to cope with that).
==> Yes, thats correct.

Could you please answer to my other question: is the localization calculated on a regular basis or only once, stored in a cookie and reused for all calls ? I ask as my application on mobile is ment to provide the distance of interesting locations but the distance should be up to date with the user position over time.
===>
Distance based on user location is calculated every time that we get the new user location, but that is only get when on page load/reload. Meaning, it won't change constantly, as the user moves, but only after page reloads.

#2515297

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.