MapBox get City/location name from long and latit

I'm having 2 questions.
In my remote database a column is created as; alter table MYTABLE add column geog geography. Basically it's PostGIS extension for Postgres. With this said, i want MapBox to add the location coordinates from the map to this column. I wish i could save the name of selected point into my table. If it's hard, i could save coordinates to my db. How do i save this MapBox data (long and latitude) to my column geog. Or is there a better way?
Thanks for reading

Hey @ltfrupdt!

I'm not super familiar with this PostGIS extension but since it's an issue of passing an extended data type to your DB I wonder if disabling prepared statements on your query will help so that the query is passed exactly as constructed. Can you let me know if that works?

I know this post is old but I've managed to store the co-ordinates using

return utils.getCurrentPosition()

  1. Add as a new JS Code script
  2. Call script on Load
  3. Store data in number fields e.g. {{getCurLocation.data.coords.longitude}} where getCurLocation is the name of your JS Code script
  4. On submit, store number field values in DB:
    Eg:

Insert INTO
gg_Sightings (id, "Date", "Long", "Lat", "Markings", "Color")
VALUES
(
(
SELECT
MAX(ID) + 1
FROM
gg_Sightings
),
NOW (),
{{long.value}},
{{lat.value}},
{{txtMarkings.value}},
{{txtColor.value}}
)

With regards to saving the naming - you will need to subscribe to a geocoding service such as Google - There are open source services that offer a free API key for your REST call however once you've added the component to your library, you can then plug the data from your long lat columns and call the API to do a 'reverse' geocode call.

Resources:

Open source (free) alternative solution:

Thanks @Augustine_Whitehouse for sharing this guidance here on our public forum - I'm sure it will help others aiming to solve this use case going forward! I'll add another service that offers a geocoding API for reference, which could be leveraged with a REST API resource in your Retool instance: https://docs.mapbox.com/api/search/geocoding/ There's even a fun playground to test out building the API request with various URL parameter options.

1 Like

Thank you very much !

1 Like

Thanking you - I managed to get reverse geocoding functioning very well within my ap. Let me know if you would like me to share my findings for others benefit.

Hi @Augustine_Whitehouse ! Thank you for the update - glad to hear it. If you'd like, please consider sharing how you set up reverse geocoding in your Retool app by creating a new topic in the Community Show & Tell category! I do think others could learn from your use case :+1: Here are some suggestions for items to include:

Tips for high quality Community Show + Tell Posts:

  • Artifacts: include a demo via a Loom video, screenshots, code snippets, and/or json exports so that folks can easily digest your content or even take action to build with your example themselves!
  • Tell a bit of a narrative around why this is impactful to your business, or to a particular industry or use case.
  • What else do you want to explore or encourage others to share on this topic going forward? Share next steps and/or a question or invitation to discuss a topic.