Skip Navigation

[Closed] Need help understanding wpv-gelocation – Is ajax an option?

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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 Waqar 4 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1675353

Tell us what you are trying to do?
When a user clicks a page with a view that requires their location they are prompted by their browser to allow or block this information.

I have a view set up for both cases. If it's Allow they get the automatic geolocation view and if they respond Block they get a view they uses url_param for the distance query filter.

When the user chooses block, there is no issue. The problem is that "Allow" requires a reload according to the wpv-geolocation documentation, and this takes way too long. I will concede that the pages these view are implemented on are a bit slow to load, but I have to ask, is the reload even necessary? Why is Ajax not employed for this? The "Use My Location" input manages everything through ajax, so why is this not an option for views that use a 'viewing user's location' as the distance query filter? Why does wpv-geolocation require reload?

I have tried a few tricks to offset this load time, like using JS to only reveal the view after the user has responded to the prompt with either allow or block. But then after revealing the view, the page reloads which doesn't help much and is still very jarring for first time visitors.

I had some success using the view with url_param with hidden inputs, where JS would automatically click the "Use My Location" input on load, but at least one test user had inconsistent results... and I don't think it should be necessary to set it up that way.

Is there any documentation that you are following?
wpv-geolocation and other map documentation

Is there a similar example that we can see?
I'll share it privately

What is the link to your site?
I'll share it privately

#1676101

Hi,

Thank you for contacting us and I'd be happy to assist.

As you noted, the way "wpv-geolocation" shortcode works, it shows the user location consent and if it is granted, saves the location cordinates in browser's cookie ( key: toolset_maps_location ) and then reloads the page, so that any content that was enclosed within this shortcode can be properly rendered.

I'm afraid, there is no built-in and/or simper way to bypass this page re-load but you can use a following workaround to speed things up:

1. Instead of asking for user location consent on the actual page which may be slow due to other content, you can create a new page named for example "User location consent" just for this purpose.

This page will only have the code for user's location consent, so it should be quicker than loading the actual page.

2. You can register a new custom shortcode, that redirect to a specified page using the "id" attribute:


add_shortcode('custom-safe-redirect', 'custom_safe_redirect_func');
function custom_safe_redirect_func($atts) {

	$a = shortcode_atts( array(
		'id' => '',
	), $atts );

	$url = get_permalink($a['id']);

	if ($url) {
	ob_start();

	echo '<script type="text/javascript">';
	echo 'window.location.href="'.$url.'";';
	echo '</script>';
	
		return ob_get_clean();
	}
	
}

3. On this new "User location consent" page, you'll add this custom shortcode, wrapped in "wpv-geolocation" shortcode:


[wpv-geolocation message_when_missing="We need your location to show this content"]
[custom-safe-redirect id="123"]
[/wpv-geolocation]

Note: you'll replace 123 with the actula ID of the page, that holds the view that is for "user location allowed" case.

When a user will visit this new page, he/she will see a user location consent, and only if it is allowed, will be automatically redirected to the view for the user location allowed case.

For the other case, you can include a link to a page that holds the view that is to be used when user doesn't allow location access, below the "[wpv-geolocation]" shortcode.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1677087
distance-missing.JPG

I appreciate you taking the time, but can't see how that solution is any less jarring.

I've gone back to my JS set up where instead of getting a user's location in the query filter, I use "address/coordinates provided using toolset_maps_distance_center URL parameter" and have JS click the "Use My Location" button on load. Since it's set to "AJAX results update when visitors change any filter values", this works pretty well.

BUT there is one very weird problem.

In my loop is

[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-dealer-address' decimals='2' unit='mi']

But the distance value only shows up on the first two results and every subsequent result is blank.
(Update: Sometimes it's the first three, sometimes it's the first 4)

Also, while my testing is very limited, it's just happening on desktop so far. On mobile we have thus far been getting the distance.

#1678155

Thanks for the update.

Can you please share temporary admin login details along with the link to a page where this shortcode can be seen?

I'll be in a better position to understand how this view is set up and then test it on my own website.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

The topic ‘[Closed] Need help understanding wpv-gelocation – Is ajax an option?’ is closed to new replies.