Geography Type - How to populate 762 rows?

Options

How do I populate 762 rows with the Geography type, i.e. not manually. 

I discovered the Geography type after I read the question from @Josh Nelson . This feature is great and could enhance my application significantly.

I have a table called Places - screenshot below. I have the latitude and longitude in separate columns as decimal types (that's how the data came). How to I fill the latlong column?

My app is not live so I am free to blitz the table if necessary.

Option 1. 

If the geo_point values are JSON text strings, I could export the data and use Excel to create the Geography values and import the data back to the table. Would the geo_point values be valid if added as text via an import?

Option 2.

Process all the records in Xano with a loop function? This would involve building the JSON string on the fly and updating each record, inside the loop. Is this possible or feasible?

Any suggestions greatly received.

Thanks again for this cool feature.

Tony



Tagged:

Best Answers

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Answer ✓
    Options

    The geo_point is a JSON object, with the following structure:

    {"type": point, "data": {"lat": "latitude here", "lng":"longitude here"}}

    Using your #2 option, you can easily loop through your records and reconstruct your separate values as a JSON object for insertion into a geo point field type.

  • Will
    Will Member
    Answer ✓
    Options

    I did! Thanks. The issue was related to the debugger - had to uncheck "
    INCLUDE VARIABLE DETAILS DURING RUN" and it worked after that.

Answers

  • Mr_English
    Options

    @Chris Coleman Thanks, I will give that a go.

  • Mr_English
    Options

    @Chris Coleman

    In case this will be of interest to anyone, here is my solution. My tables is called ‘places’. I had latitude and logitude values and I wanted to create a geo_point.

    Screenshot 1 - empty latlog column

    Screenshot 2 - geo-points added

    Solution

    This was useful - https://geojson.org/

  • Will
    Will Member
    edited May 2023
    Options

    @Mr_English you just saved me hours. thank you

    EDIT: maybe i was too quick here, i'm wondering why this isn't working because I think i've replicated exactly what you did:

    Error:

    If you have any suggestions, I'm all ears. Thanks

  • Will
    Will Member
    Options

    Here's an update: I got it working, but because it's over 6k records it seems to be too much for the loop to handle:

    pretty unfortunate that there's really no solution to this @Xano Support Chat

  • Mr_English
    Mr_English Member
    edited June 2023
    Options

    @Will Hi - did you resolve this in the end?

  • Mr_English
    Options

    @Will I am running this api again on Spanish cities.

  • Will
    Will Member
    Options

    @Mr_English What error are you getting specifically?

  • Mr_English
    Options

    @Will No problems!

    I meant that I imported a list of Spanish and Italian cities, that came with lat / long data. I then ran them through the api to create the geo point. It worked perfectly - it's quite fun to see the pins on the map!

    Btw - I had a list of cities in the UK and instead of showing UK, I wanted to show the country within the UK (i.e. England, Wales, Scotland or Northern Ireland). I exported the data and got ChatGPT to identify the country for each place, based on the lat / longs. I cleared the places table and re-imported the UK countries, then ran these through the API to get the geo-points. There is probably a clever way I could have done this in Xano, but ChatGPT handled the job easily.

  • Will
    Will Member
    Options

    Awesome, thanks for that info and checking if I was able to get it to work. Unchecking the option "INCLUDE VARIABLE DETAILS DURING RUN" ended up being the solution if anyone else runs into the same error!