Skip Navigation

[Resolved] How to centralize the map on the current location of the user

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1334271

I want map be centralized on the current location of the user. I did not find how to do it.

#1334323

I saw there are the attributes "general_center_lat" and "general_center_lon" to centralize the map given latitude and longitude. So, the question is how can I retrieve the current user location to fill out these attributes ?

#1334573

Hello, the feature to automatically center the map based on the visitor's location when the map loads is not available, but you can display a marker at the visitor's current location and use the Focus on Marker shortcode to generate a text link that will allow visitors to center the map on their location: https://toolset.com/documentation/user-guides/maps-shortcodes/#map-focus-on-marker

The User's location is not publicly available through any API at this time. You're welcome to submit new feature requests if you'd like to see these ideas added in an upcoming version of the Toolset suite:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1337633

I did not understand: text link that allow to center the map ? What you mean "text link" ?

#1337997
Screen Shot 2019-09-11 at 11.48.15 AM.png

I made an example you can see here:
https://christiancox-22119-rel-1.discover-wp.com/focus-on-marker-test/
The browser will ask for permission to use your location. You MUST allow location access to see the example working. Click "FOCUS ON MY LOCATION" after both markers are shown. There should be one marker at Washington DC, USA, and another at your current location. When you click "FOCUS ON MY LOCATION" the map should zoom to your location.

First, you will create a Marker that displays at the User's location. Check this document for more information: https://toolset.com/documentation/user-guides/display-on-google-maps/displaying-markers-on-google-maps/#displaying-current-visitor-location

Then you can use the "Focus on Marker" feature to generate a text link. See the screenshot here. The text link can say something like "FOCUS ON MY LOCATION". When the User clicks this link, the map will focus on their location.
The documentation for this shortcode is here: https://toolset.com/documentation/user-guides/maps-shortcodes/#map-focus-on-marker

Here is the code I used to display the map, the two map markers, and the focus on marker text link:

[wpv-map-render map_id="map-test-focus" map_height="500px"][/wpv-map-render]

[wpv-map-marker map_id='map-test-focus' marker_id='marker-user-focus' map_render='wait' current_visitor_location='true'][/wpv-map-marker]

[wpv-map-marker map_id='map-test-focus' marker_id='marker-other-address' address='1600 Pennsylvania Avenue Northwest, Washington, DC, USA'][/wpv-map-marker]

<a href="#" class="js-wpv-addon-maps-focus-map" data-map="map-test-focus" data-marker="marker-user-focus">FOCUS ON MY LOCATION</a>

Let me know if you have questions about this.