Skip Navigation

[Resolved] Geolocation issues

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 7 replies, has 2 voices.

Last updated by Minesh 9 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2684119

Hi,
I have a geolocated classic view that is supposed to show events within 50 km from the user location, without a map. The view triggers the browser position tracking window, but even though the user selects ALLOW the view displays the message "Your location is needed to show this content.". BUT if I add whatever map to the same page of the view then also the view displays its output correctly (and cannot go back to trigger the position tracking window, it stays selected even deleting cookes, etc).
It looks like showing a map on the page is mandatory to get the geolocation fully working. Is this true or is there anything I don't understand ? In this view I have added [wpv-geolocation] like this:
[wpv-geolocation]
[wpv-layout-meta-html]
[/wpv-geolocation]
Is this correct ?
I also have another similar NOT geolocalized view, showing all events. I'd like to display the output of the geolocalized one if the user allows his position tracking OR the other not-geolocalized one if the user blocks the tracking, how do I test the user selection before the content is shown on the page? I tried with conditionals, they work but the browser position tracking window doesn't show up anymore.
Please let me know
thanks
Regards
Nicola

#2684185

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Please check few important things that your site must be running with HTTPS:
- https://toolset.com/course-lesson/filtering-and-ordering-map-markers-by-distance/#filtering-markers-by-distance

Following hint may be useful for you as well:
- https://toolset.com/forums/topic/geo-search-not-working-if-location-is-not-in-dataset/#post-2649411

When the "[wpv-geolocation]" shortcode is used, "Your location is needed to show this content." message is shown, until the visitor agrees to share location information.

The following screenshots show how this consent dialog appears in different browsers:
- Chrome: hidden link
- Firefox: hidden link
- Internet Explorer: hidden link

The conditional content based on the user location be used with another shortcode "toolset-maps-distance-conditional-display" which conditionally shows or hides the content:
- https://toolset.com/documentation/user-guides/maps-shortcodes/#toolset-maps-distance-conditional-display

For example:

[wpv-geolocation]
[toolset-maps-distance-conditional-display location='Spain' distance='100' display="inside" unit='mi']
Show content to visitor who is inside the 1000 miles radius from Spain's central location.
[/toolset-maps-distance-conditional-display]
[/wpv-geolocation]
#2684285

Hello Minesh,
You wrote: When the "[wpv-geolocation]" shortcode is used, "Your location is needed to show this content." message is shown, until the visitor agrees to share location information.
Ok, but what happens in my case is that the message is shown also if the visitor agrees, UNLESS a map is shown on the page.

toolset-maps-distance-conditional-display "Shows or hides its content based on the distance of the current visitor from the given point", but this isn't what I am looking for. I need to show content based on the Agree/Block selection in the consent window. If he agrees I show the geolocated content, if not just a generic content.

#2684407

Minesh
Supporter

Languages: English (English )

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

Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2684422

Here it is

#2684520

Minesh
Supporter

Languages: English (English )

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

What if you try to add the following shortcode to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

function func_get_maps_location_cookie() {
    if (!isset($_COOKIE["toolset_maps_location"]) or  (isset($_COOKIE["toolset_maps_location"]) and $_COOKIE["toolset_maps_location"]=='')) {
      return 0;
    }
   return 1;
}
add_shortcode( 'get-location-cookie', 'func_get_maps_location_cookie' );

Then, register the shortcode name get-location-cookie at:
=> Toolset => Settings => Front-end Content => Third-party shortcode arguments
- https://toolset.com/documentation/legacy-features/views-plugin/shortcodes-within-shortcodes/#third-party-shortcode-arguments

Then to the place where you are trying to display your view, you should display the view as given under:

[wpv-geolocation]
[wpv-conditional if="( [get-location-cookie] eq 1 )"]
    [wpv-view name="view-distance-filter"]
[/wpv-conditional]
[/wpv-geolocation]

[wpv-conditional if="( [get-location-cookie] eq 0 )"]
    [wpv-view name="view-distance-filter"]
[/wpv-conditional]

Where:
- Please replace view-distance-filter with your original view slug.

By default - it will show all the content from view but as soon as you accept the location sharing consent, it will display the filtered result based on your location.

I hope this helps you to resolve your issue.

#2684913

Hello Minesh,
I implemented your solution, just renamed it as [geolocation-test]. What happens is that the consent window is always triggered but:
- if I select BLOCK: [geolocation-test] returns 0 and the NOT geolocalized view is never shown. If I open another geolocated page (without this conditional) it correctly detects that the position tracking is not allowed and the map is not shown.
- if I select CONSENT: [geolocation-test] still returns 0 with the message "Your location is needed to show this content", the page reloads but [geolocation-test] still returns 0. If I open another geolocated page (without this conditional) it correctly detects that the position tracking is allowed and the map is shown.
The page where these views are supposed to be shown is my homepage. I have created another test page and added the same code, this ALWAYS returns 1, no matter what consent! this doesn't make much sense to me. Any clue ?

#2684924

Minesh
Supporter

Languages: English (English )

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

I see you are using Lightspeed cache plugin.

Can you please clear all the cache and then try to disable the plugin and then also clear all cookies and start testing from first and check how it goes?

#2684927

Hello Minesh,
I tried many solutions, but I see this test/conditional is a never ending mess, results change every time due to caching and possibly to other geolocated elements on the page which can conflict. In order not to waste your time, I decided to go for a different solution that always work: show the non geolocated view to loggedout users and the geolocated view to loggedin users. This is possible thanks to blocks visibility rules. If under other circumstances you can find way to show content depending on consent please publish a document so that everyone can benefit.
Thanks and regards
Nicola