Manual Geocoding String

Hi!

I am pretty new to Wix and am stumped with a problem I’m trying to solve

I have a page that records address inputs. I did not use the address input field as this is sometimes inaccurate (specifically with flat numbers/etc). Therefore I capture address data into a text input from all address fields and want to geocode it.

I have searched around and seem to have the backend code applicable in place, but have no idea how to use get this to work with the user input? Essentially all I’m looking for is to geocode the address string and then capture both the address string and the geocode address (as an address type) into a collection.

The backend code in place is:

import { fetch } from ‘wix-fetch’

const baseURL = “https://maps.googleapis.com/maps/api/geocode/json?
const key = “MYAPIKEY”
export function geocodeAddress ( query ) {
let url = baseURL + “address=” + query + “&key=” + key
return fetch ( url , { method : ‘get’ }). then ( httpResponse => {
if ( httpResponse . ok ) {
return httpResponse . json ()
}
})
}

Assuming the address string I have captured from users is “#googleAddress”, how would I go about geocoding the address string to get the final output prior to storing in the collection?

FYI this articles around geocoding on wix helped but did not result in an answer

Thanks in advance

Hello! Are you asking how to pass the string from the page code into the backend function query param and then update your collection with the response from the API?