I am trying to: I used the wpv-geolocation shortcode on a page to ask the user to enable localization on the mobile (in order, on other pages, to show distances between the user and some resources).
Link to a page where the issue can be seen:
I expected to see: each time a user access the page the first time, the smartphone should ask her/him to autorize the geolocation.
Instead, I got: the behaviour is erratic: sometimes the question is asked, sometimes not. This is due to a bug in your code, as previously investigated / discussed in the ticket "Strange behaviour of toolset-maps-distance-value on mobile". I proposed a solution (in the ticket), but the bug is still there. So I can fix it by modifying your code, but each time a new version of the map plugin is delivered, my fix is overwritten.
Hi,
Thank you for contacting us and I'd be happy to assist.
Instead of adding the changes to the Toolset Maps plugin's file, have you tried adding the custom script to load the same function on the 'ready' event?
For example:
function custom_maps_location_js_after() {
if (!isset($_COOKIE["toolset_maps_location"])) {
?>
<script id='custom-toolset-maps-location-js-after'>
jQuery( window ).on( 'ready', function() {
WPViews.location.initWithReload();
} );
</script>
<?php
}
}
add_action( 'wp_footer', 'custom_maps_location_js_after' );
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Note: this function will load this script on all pages when the location cookie 'toolset_maps_location' is not set. If it works, you can further adjust this code to only make it load on specific pages where the geolocation shortcode is used.
I hope this helps and let me know how it goes.
regards,
Waqar
Hello Waqar,
thanks for your answer / suggestion. Actually, as I mentioned in my past ticket, the issue is due to problem with jquery (from my past ticket) : "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)."
The change I suggested (and implemented on my side was to cope with this:
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;
});
But you are right, I can implement my own short code instead of using wpv-geolocation. That said it's a pity not to fix this bug as other user will face it (and like me, spend a lot of time to investigate the origin).
Cheers
My issue is resolved now. Thank you!