Can I get the LatLong capture from the Adress...

Can I get the LatLong capture from the Adress point?

0 18 4,125
  • UX
18 REPLIES 18

Harry2
New Member

@Marlon_Xavier_Medina Hi Marlon, if you want to convert an existing address to LatLong, Iโ€™m afraid this is currently not possible in the app. However, if you want to capture the current location of the app user, you can learn how to do so in this article:

help.appsheet.com - Capturing GPS Location Capturing GPS Location help.appsheet.com

@Marlon_Xavier_Medina what you are asking is a reverse geocode and Iโ€™m afraid thatโ€™s not possible with AppSheet right at the moment. However, itโ€™s doable with scripting.

all right. When you mention โ€œscrptingโ€ means that it will work in another platform ?

@Marlon_Xavier_Medina can you clarify what do you want to mean with"โ€ฆit will work in another platformโ€ฆ"?

@LeventK this sounds like what I need. If I can explain
I have an app that allows addresses to be entered. For a maintenance activity, I want to allow a user to pick an address thatโ€™s โ€˜closeโ€™. I naturally thought I could calculate a virtual column [Distance from HERE to Address] and then ORDERBY( โ€ฆ[Distance from HERE to Address]โ€ฆ).

But of course distance calculations donโ€™t work with addresses.

Hence the need to be able to convert Addresses to LatLong.

Since itโ€™s plotted on a map there must already be a calculated LatLong for each address in my list. So may we access that please?

And if it needs a geocoding call like this then how may I code it so that the values are calculated when a record is saved?

THanks

As Andrew_Smith1 says, it already get the lat long to place the pin on the map, but i cant find a way to accually use that lat long in a DISTANCE(HERE(),[Address]) expresion.

I dont know if it is only me, but i dont know the lat long of a worksites address by heart and it is not many costumers that specify the lat long in their postal address.

Will it be possible to get a function like GEO_CODE([ADDRESS]) so it will be possible to make a DISTANCE(HERE(),GEO_CODE([Address]))

PS. I am pretty new to APPSHEET and i love it, maybe i have to ask this as a feature request somewhere

Please see the following:

Vote for the feature here:

It would be better if you could do this in Appsheet, but as otherโ€™s have said itโ€™s not available right now. I overcame the issue by putting an extra column in my google sheet titled LatLong and used a script for a custom function.
*/
function GEOCODE_GOOGLE(address) {
if (address.map) {
return address.map(GEOCODE_GOOGLE)
} else {
var r = Maps.newGeocoder().geocode(address)
for (var i = 0; i < r.results.length; i++) {
var res = r.results[i]
return res.geometry.location.lat + ", " + res.geometry.location.lng
}
}
}

@Brady_Lovell built the script and posted it on another chain.

Once the script is in I use the function geocode_google(address) to get the latlong.
Then I created a virtual column in appsheet distance(here(),[LatLong]) and sorted my result by distance.

Once again it would be better as a native appsheet function, but until that happens this seems to do the trick. Hope this helps

FYG

This is another script sample, I scripted for GAS (Google App Script), which return driving distance between location, A to B.

First function returns driving distance in KM using Address value, while the second function return the same from lat/long for A and B.

function DrivingKM(origin, destination) {
var directions = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.setMode(Maps.DirectionFinder.Mode.DRIVING)
.getDirections();
return directions.routes[0].legs[0].distance.value/1000;
}

function DrivingKM(lat1,long1,lat2,long2) {
var directions = Maps.newDirectionFinder()
.setOrigin(lat1,long1)
.setDestination(lat2,long2)
.setMode(Maps.DirectionFinder.Mode.DRIVING)
.getDirections();
return directions.routes[0].legs[0].distance.value/1000;
}

I raised feature request to do the same calculation within Appsheet with their own function natively, but until they implement, this is only the solution with me to achieve my goal.

If you want to get the distance by โ€œwalkโ€ instead of โ€œdrivingโ€, change the syntax to

.setMode(Maps.DirectionFinder.Mode.Walking)

Hi David,
excuse the question, but can I use your script? once created can i use it in my project created with appsheet? Thank you

Giampaolo

Feel free to use the script however you want.

Iโ€™m having the same trouble with calculating the distance and came across your solution. However, I can not understand where to build the script mentioned by you. Can you please explain? Thanks in advance!

Menu in the Google Sheets: Tools/Script Editor

Thanks for your reply! Can you share an article or more information on how then to use the script into my app? I couldnโ€™t find any helpful information related to AppSheet.

You may find useful information on Stackoverflow for example, this forum is not dedicated to helping on Google Apps Script.

Also, This Youtube channel here is really well made in my opinion for learning basics:

Basically:

  • open the apps script editor
  • copy-paste the code provided above in @tsuji_koichi 's post (pick the 1st piece of code or the 2nd one depending on your calculation preference : with address or lat/long)
  • save
  • in the menu, pick the function DrivingKM click on run
  • accept scope authorizations if asked
  • go back to the sheet
  • type =DrivingKM(yourAddresse, yourAddress2)
  • tadaaaa !

Iโ€™m not 100% sure about procedure, but it should be something really close to this.

Hi! I keep getting TypeError: Cannot read property โ€˜mapโ€™ of undefined. Am I missing something?

Hi Marlon.

I was expecting this feature can help overall all users. As my Map app is useless at the moment. I found my way to resolve it following way.

You can use GeoCode from Awesome Table addon from Google Sheet.
here is the Youtube video

Hope this helps

Top Labels in this Space