Yes - there is no native feature available to record the user's current location. It requires custom code and kind of workaround to register it.
Theoretically - You should:
- Create a custom post type User Locations
- Create a custom field group and attach that field group to display with "User Locations" post type and add the single-line field that will hold the current user location.
More info:
=> https://toolset.com/documentation/getting-started-with-toolset/structure-your-data-with-custom-post-types-fields-and-taxonomies/
=> https://toolset.com/documentation/user-guides/custom-content/using-custom-fields/
If you want multiple fields that should hold the information of current user location, like lat and long co-ordinates you want to store in different fields then I would suggest you should create a Repeating Field group and assign that to your post type.
=> https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/
Once you have the structure ready:
- you should create a Toolset form to create the content for post type "User Locations"
- switch to the export mode and add replace the form content with the following code:
- Add hidden fields that will hold the current user information using generic fields:
[credform]
[cred_field field='form_messages' class='alert alert-warning']
[cred_generic_field type='hidden' field='hidden_lat']
{
"default":""
}
[/cred_generic_field]
[cred_generic_field type='hidden' field='hidden_long']
{
"default":""
}
[/cred_generic_field]
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]
- Add the following code to Form's JS editor section
jQuery(document).ready( function($) {
navigator.geolocation.getCurrentPosition(function(position){
$('input[name="hidden_lat"]').val(position.coords.latitude);
$('input[name="hidden_long"]').val(position.coords.longitude);
});
});
- Save the form and create a new page and add this form to that page
- Once the page loaded if you will check the page source, you will notice that the fields hidden_lat and hidden_long will contain the current user lat,long values respectively.
Now, the next step is to submit the form by clicking on the submit button but how to save content in the backend is depends on with what structure you would like to go with. Single field or Repeating field as I mentioned before. At this moment it will just create a new entry but no co-ordinates will be stored.
I hope based on this information at least you will now get the idea and please get in touch with me if you need further assistance on this.