Unable to retrieve multiple locations from location field.

166 views
Skip to first unread message

Brandon M.

unread,
Oct 30, 2024, 12:52:53 PM10/30/24
to mementodatabase
Hello everyone,

I have been scouring the wiki and searching through this group for anything that might help me, but I have uncovered nothing.

I am trying to write a JS field that calculates the perimeter of the listed points in the field. For simplicity sake, let's define the name of our location field as "Zone Location" and the JS field as "Perimeter"

I am able to retrieve the first location, but I cannot figure out how to access any of the other locations listed. Below is the code that is contained in my Perimeter field.

// Attempt to retrieve coordinates from the "Property zone 1" field
var location = entry().field("Property zone 1");

if (location && location.lat !== null && location.lng !== null) {
    // Return lat and lng as a string to confirm access
   "Location: " + location +"\nLatitude: " + location.lat + ", Longitude: " + location.lng;
} else {
   "Error: 'Property zone 1' does not contain valid location data.";
}

I don't seem to be retrieving an array, or any additional information from the field. If I change which coordinate appears at the top of the list, the information in my Perimeter field updates accordingly.

I am trying to pull an unknown number of coordinates from the location field. Am I just missing something here? I was attempting to use the .attr function as well, but that only resulted in errors. I don't see any way to define that I want to retrieve all of that information. Is this possible with memento?

Thank you in advance.

Er Mo

unread,
Oct 30, 2024, 1:51:02 PM10/30/24
to mementodatabase
Hallo
Der Feldtyp " JS " kann nur auf den Eintrag zugreifen in den er Steht . Es müssen alle daten die du Abfragen wilst in den selben Eintrag stehen

Hello
The field type "JS" can only access the entry in which it is located. All the data that you want to query must be in the same entry

Ernst

Brandon M.

unread,
Oct 30, 2024, 2:16:54 PM10/30/24
to mementodatabase
Hello Ernst,

I may not have been completely clear with what I am trying to accomplish. Below I have included a screenshot of a test record showing four coordinates occupying the "Zone Location" field. Of which I am only able to access the first record. I have also included the code contained within both of the Permieter fields to document what I have tried so far. As you can see, all four coordinates are contained in the same location field.1000000194.jpg

Perimeter Result

// Attempt to retrieve coordinates from the "Property zone 1" field
var location = entry().field("Property zone 1");

if (location && location.lat !== null && location.lng !== null) {
    // Return lat and lng as a string to confirm access
   "Location: " + location +"\nLatitude: " + location.lat + ", Longitude: " + location.lng;
} else {
   "Error: 'Property zone 1' does not contain valid location data.";
}

Perimeter

field("Property zone 1");

I have checked the data type, and it doesn't appear to be returning the results in an array like a linked entries are. I was able to easily pull the linked entries to create an inventory library that was automatically adjusted by a work order library, and access each object's attributes from the returned object, but I can't seem to find a way to get a similar result here.

Er Mo

unread,
Oct 30, 2024, 2:43:37 PM10/30/24
to mementodatabase
Hallo
Wieso teilst du nicht die Werte auf 4 Felder auf . A B C D  . So kannst du jeden Werd einlesen .

Hello
Why don't you split the values ​​into 4 fields. A B C D. That way you can read in every value.

Ernst

Brandon M.

unread,
Oct 30, 2024, 2:50:04 PM10/30/24
to mementodatabase
Hello Ernst,

The problem with that is that there could be an unknown amount of points to create this shape. I am trying to write a script that will take a list of an unknown number of points (minimum 3) and then calculate things such as the perimeter and area of the polygon.

I was hoping there would be a better way rather than creating 100 possible location fields, with dependancies to only appear if the previous one is populated. Especially since I haven't found a way to limit the number of locations that can be entered into a location field.

The idea is to try and collect these points, use them to calculate information regarding the area contained within, so that I can write a script that will be able to automatically estimate the costs of services to the customer. Allowing me to quickly walk or plot the property in Google maps, and give them an instantaneous quote.

Thank you for continued assistance.

Er Mo

unread,
Oct 30, 2024, 3:15:59 PM10/30/24
to mementodatabase
Hallo
Ich habe eine Bibliothek mit den Grenzsteinen von einen Grundstück . Hir kann ich die Entfernung zwischen 2 Punkter errechnen . Dabei ist jeder Punkt ein Eintrag der die GPS Daten und  Grundstücknummer enthält . Zum Berechne der Entfernung wird ein Ausgangspunkt ( Grenzstein ) ausgewählt und Markirt . Wenn ich nun einen anderen Grenzstein auswähle , kann ich die Entfernung zu den Markirten Grenzstein errechnen . In deinen Fall würde ich die GPS Daten mit den Namen von Kunden oder Grundstück speichern . Zum Berechnen kann ich alle Daten für diese Grundstück suchen und Abfragen . Oder ich erstelle eine Bibliothek zum Rechen in der die Daten kopierd werden . Nach erhalt des Ergebnisses können die Einträge wider gelöscht werden .

Hello
I have a library with the boundary stones of a property. Here I can calculate the distance between 2 points. Each point is an entry that contains the GPS data and property number. To calculate the distance, a starting point (boundary stone) is selected and marked. If I now select a different boundary stone, I can calculate the distance to the marked boundary stone. In your case, I would save the GPS data with the names of the customer or property. To calculate, I can search for and query all the data for this property. Or I create a library for calculations in which the data is copied. Once the result is received, the entries can be deleted again.

Ernst

Brandon M.

unread,
Oct 30, 2024, 4:24:54 PM10/30/24
to mementodatabase
Hello Ernst,

While that would work, creating a whole library just for the temporary creation of nodes seems like a clunky work around that would also require me to redo all of my points. The primary reason I am trying to pull all of the JSGeolocation objects from a single Location field is that I already have thousands of boundary points stored in a live database in this fashion.

My attempts to restrict a location field to one entry have failed, and the ability to show/hide a location field cannot be based on a Location field's empty status. So that pretty much rules out the possibility of the A B C D idea, as it's incredibly clunky and prone to user error.

Since posting my initial question, I have also tried getting this information via a Trigger script and an Action script. All attempts result in just a singular JSGeolocation object, regardless of how many are present in the entry.

Am I correct in understanding that a Location field can only return a singular JSGeolocation object? There is no way to pull any other objects from the field?

Additionally, if I pull the JSGeolocation object, and then store the Long/Lat in an array, is there a way for me to remove just the first entry in the Location field? Maybe I could just brute force converting them into real values with an action script that reads the field, deletes the first entry, rinse and repeat until the field is empty?

I need to retain all of the Long/Lat points, and the order in which they were recorded for me to begin the next step of my project.

Thank you for your continued assistance.

Bill Crews

unread,
Oct 30, 2024, 5:13:38 PM10/30/24
to Brandon M., mementodatabase
In a JavaScript field, you don't use entry(). Also,  you access a Location field with aGeolocation object.  See wiki here...

Object JSGeolocation

This object contains the information stored within a Location field and provides properties and methods for use in accessing and manipulating this information.

When an Entry object's field() method is called, if the Memento field type is Location, a JSGeolocation object is returned.

If the Location field contains multiple locations, use hasNext and next to retrieve them.
JSGeolocation properties

    address
        Address for this Location

    hasNext
        Returns TRUE if there is a next JSGeolocation object, otherwise FALSE

    lat
        Latitude, as a Real

    lng
        Longitude, as a Real

    next
        Returns the next JSGeolocation object, if there is one.

You make a loop starting with the object in [0], and if hasNext is true, keep looping via next until hasNext is false. Then do your calculation and return the result of that calculation. 


--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/23b569eb-22cb-4ded-8145-0186bc289d38n%40googlegroups.com.

Bill Crews

unread,
Oct 30, 2024, 5:15:21 PM10/30/24
to Brandon M., mementodatabase
You could use an array to hold the values before the calculation (or calculate on the fly).

Brandon M.

unread,
Oct 30, 2024, 6:12:37 PM10/30/24
to mementodatabase
Hello Bill,
Thank you very much for that information, I'm not sure how I missed it in the wiki. I believe this is exactly what I'm  looking for.

I will report back with the outcome. Thank you for taking the time to reply to my inquiry.

Bill Crews

unread,
Oct 30, 2024, 6:18:07 PM10/30/24
to Brandon M., mementodatabase
I'm sorry I didn't send you actual code. Coding is hard for me these days, and I keep making silly mistakes. But let me know if you have trouble (privately or not), and I'll help you through.

Mmm

unread,
Oct 30, 2024, 9:23:18 PM10/30/24
to mementodatabase
Скрипт поля JS "Perimeter":

if (field("Zone Location")){

    const line = (location) => {
        return "Location: " + location +"\nLatitude: " + location.lat + ", Longitude: " + location.lng;
    }

    let locations = []
    let geo = field("Zone Location");
    locations.push(line(geo));

    while(geo.hasNext) {
        locations.push(line(geo.next));
        geo = geo.next;
    }

    locations.join('\n\n');

} else {
    "Error: 'Zone Location' does not contain valid location data.";
}

Шаблон библиотеки с примером:

четверг, 31 октября 2024 г. в 01:18:07 UTC+3, bill....@gmail.com:

Mmm

unread,
Oct 30, 2024, 9:49:32 PM10/30/24
to mementodatabase
Дополнение:

Строка кода:
const line = (location) => {
    return "Location: " + location +"\nLatitude: " + location.lat + ", Longitude: " + location.lng;

при выполнении может вызвать ошибку: 
"TypeError: TypeError: redeclaration of const line." 

Замените на строку:
let line = (location) => {
    return "Location: " + location +"\nLatitude: " + location.lat + ", Longitude: " + location.lng;
}

Новый шаблон с примером (шаблон из сообщения выше удалён):

четверг, 31 октября 2024 г. в 04:23:18 UTC+3, Mmm:

Brandon M.

unread,
Oct 31, 2024, 8:48:34 AM10/31/24
to mementodatabase
Good morning Bill and Mmm,

Thank you for your help, my main issue was mishandling the JSGeolocation object.  Now that I understand my mistake, correcting the issue in my code was trivial. 

Below you will find my less-than-elegant test script, now that this piece of the puzzle is solved, I should be off to the races again.

// Retrieve the Location field
var locationData = entry().field("Property zone 1");
var coordinatesList = "";

// Check if locationData exists and is a JSGeolocation object
if (locationData && locationData.lat !== undefined && locationData.lng !== undefined) {
    // Loop through each point if multiple points exist
    while (locationData) {
        // Append the current location's latitude and longitude to the list
        coordinatesList += "Latitude: " + locationData.lat + ", Longitude: " + locationData.lng + "\n";
        
        // Check if there is a next location
        if (locationData.hasNext) {
            // Move to the next location
            locationData = locationData.next;
        } else {
            // No more locations
            break;
        }
    }
    
    // Display the list of coordinates in the "Perimeter" field
    entry().set("Perimeter", coordinatesList);
} else {
    entry().set("Perimeter", "Error: 'Property zone 1' does not contain valid location data.");
}

@Bill
No worries friend, you were more than helpful. I was losing my mind trying to find what I was looking for in the wiki.

As always, much appreciation to everyone for their continued assistance to see this problem through to the end!

Bill Crews

unread,
Oct 31, 2024, 11:24:06 AM10/31/24
to Brandon M., mementodatabase
I'm glad you are on your way.

As an example of my confusion, I thought you were looping through multiple links and then through multiple locations within each link, and I thought you wanted each link to be to the entries linked and not only to the most recently created link, as David was suggesting. 

Then, I'm confused, as I thought you wanted to return the perimeter as the value of a JavaScript field rather than setting the value of another field.

My inability to think through such things any more is why I limit my responses nowadays, in case anyone is interested.

Nevertheless, you are on your way!


Reply all
Reply to author
Forward
0 new messages