Skip Navigation

[Resolved] Erratic execution of the short code wpv-geolocation 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by patrickF-7 11 months, 1 week ago.

Assisted by: Waqar.

Author
Posts
#2607183

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.

#2607511

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#2608137

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

#2608139

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.