Skip Navigation

[Resolved] Record user location in field

This support ticket is created 5 years, 1 month 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
- 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 5 replies, has 2 voices.

Last updated by Minesh 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1445417

Tell us what you are trying to do?

create a system to track multiple user's locations on a map, specifically mobile security units for tracking at a dispatch center.

Ideally, the user would click a button and their current location would be stored in a field in the database.

Is there any documentation that you are following?

I haven't found any.

Is there a similar example that we can see?

hidden link

What is the link to your site?

I have not built it yet, I wanted to ask if this was even possible?

#1446181

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The toolset offers a way to filter the results with the current location as well as with distance.
=> https://toolset.com/documentation/user-guides/maps/display-on-google-maps/filtering-and-ordering-map-markers-by-distance/

We do not have any way to record the current location and add it to the post. There could be a workaround I should try and check but before that, I would like to have more information;
- Will the user be able to record the location as logged in user only?
- How many times user should able to record location?
- Where you want to store/display the stored location? Is it ok if we save it brand new post type and custom fields?

#1446747

The locations would only recorded by logged in users
The recording of the location should be repeatable infinitely, but would only need to be done periodically, say every 1-2 minutes, not in real time.
The location record would be stored in a field as part of a custom post type.

I appreciate your help, thank you!

#1448379

Minesh
Supporter

Languages: English (English )

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

The locations would only recorded by logged in users
The recording of the location should be repeatable infinitely, but would only need to be done periodically, say every 1-2 minutes, not in real time.
The location record would be stored in a field as part of a custom post type.
==>
Ok.

Thanks for the clarifications but there is no such feature exists to record location periodically and this needs custom programming that is beyond the scope of our support policy. If you need custom programming for your project, please feel free to contact our certified partners:
=> https://toolset.com/contractors/

Maybe the following plugin may help you:
=> https://wordpress.org/plugins/user-activity-tracking-and-log/

Or

You should create a post type which with custom fields which will hold the location values and create a Toolset form where you should add generic hidden fields with the submit button and add the JS script that should get the user's current location and assigned the found location values to those hidden generic fields.

The following link may help you;
=> hidden link
=> https://stackoverflow.com/questions/14177647/find-user-location-using-jquery-js-without-google-geolocation-api
=> hidden link

And at last, I encourage you to file a new feature request:
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1449033

I'm not asking you for help with the periodic functionality, just the recording of the location. Obivously, if the record can be created manually, i can automate the periodic execution of it. But if I understand correctly, you are saying there is not way to record the user's location?

#1450103

Minesh
Supporter

Languages: English (English )

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

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.