How to get GPS location?

Ask your questions here.
Post Reply
skprasad
Posts: 5
Joined: 20 Oct 2020, 19:38
Name: S K PRASAD
Location: INDIA

How to get GPS location?

Post by skprasad »

Greeting,

How can I save GPS location when I press Add/Submit in entity.

Purpose; I would like to save device location for security purposes whenever a record is added.

User avatar
support
Site Admin
Posts: 3442
Joined: 19 Oct 2014, 18:22
Name: Sergey Kharchishin
Location: Russia, Evpatoriya

Re: How to get GPS location?

Post by support »

There is no feature for this.

antevasin
Posts: 47
Joined: 24 Mar 2020, 08:57
Name: Spencer Crocker
Location: New Zealand
Company Name: Antevasin Software
Contact:

Re: How to get GPS location?

Post by antevasin »

You could try the following;
Create a field of the type Map and note the ID of the field.
field type.png
Add the following code to your entities Form Configuration >> Add Javascript >> Javascript in form.

Code: Select all

let lat = '37.422176';
let long = '-122.084721';
let text = 'Google Maps Headquarters';

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(updateMap);
} else { 
	console.log( "Geolocation is not supported by this browser.");
}
function updateMap( position ) {
  lat = position.coords.latitude;
  long = position.coords.longitude;
  text = 'I woz here';
  //replace 1963 with the ID of your own map field
  $('#fields_1963').val('[map]' + lat + ',' + long + '(' + text + ')[/map]');
}
You will probably be prompted to allow the location and once that is done it should show the location on the map every time the form is edited.

skprasad
Posts: 5
Joined: 20 Oct 2020, 19:38
Name: S K PRASAD
Location: INDIA

Re: How to get GPS location?

Post by skprasad »

Thank you buddy, this code is working, thank you again.
1. How can get the Lat/Long value in text box.

antevasin
Posts: 47
Joined: 24 Mar 2020, 08:57
Name: Spencer Crocker
Location: New Zealand
Company Name: Antevasin Software
Contact:

Re: How to get GPS location?

Post by antevasin »

Change the field to be an input field instead of a map and then lose the map markup tags.
So you could replace

Code: Select all

$('#fields_1963').val('[map]' + lat + ',' + long + '(' + text + ')[/map]');
with

Code: Select all

$('#fields_1963').val(lat + ',' + long);

pepe
Sponsor
Sponsor
Posts: 442
Joined: 25 Aug 2015, 21:35
Name: Pepe
Location: Graz, Austria
Contact:

Re: How to get GPS location?

Post by pepe »

I really like this ... great information !
Using the location coordinates we could make much more use of this. Here are my thoughts:
In an earlier post, I have asked about the possibility to get weather information from third party providers, i.e., Openweathermap. There are a number of free/paid services. I am interested in API
http://history.openweathermap.org/data/ ... ty?q={city ID},{country code}&type=hour&start={start}&end={end}&appid={API key}
You can look this up on there homepage. A key needs to be generated and you need to implement it somehow into your app.
There are other apps available from Openweathermap (like forecast weather, ...).
I would like to use the history to retrieve temperature, rain, snow, cloudy, and other conditions for use in daily construction records. Site managers need to generate such a report every day. Next to a number of other pieces of information they have to take notes of weather conditions. This could be automated when that information taken from Openweathermap to Rukovotel. The API is key-based. In Javascript in forms one could invoke the weather API, get all the required information, and generate the necessary information. I just don't about detailed go-abouts.
I would truly appreciate information on this!
Thank you in advance for your input!
Best regards, Pepe

skprasad
Posts: 5
Joined: 20 Oct 2020, 19:38
Name: S K PRASAD
Location: INDIA

Re: How to get GPS location?

Post by skprasad »

Awesome Code, Thank you buddy. It's working.
antevasin wrote:
22 Oct 2020, 23:53
Change the field to be an input field instead of a map and then lose the map markup tags.
So you could replace

Code: Select all

$('#fields_1963').val('[map]' + lat + ',' + long + '(' + text + ')[/map]');
with

Code: Select all

$('#fields_1963').val(lat + ',' + long);

Post Reply