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.
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.
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 ?
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.
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.
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?
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 :
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 ...
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:
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.
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.
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.