# Address Database field type

**URL:** <https://forum.wixstudio.com/t/address-database-field-type/29593>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 13, 2020, 8:23pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593 "2020-01-13T20:23:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/patrick/32/971_2.png) [@patrick](https://forum.wixstudio.com/u/patrick)\
**Post date:** [January 13, 2020, 8:23pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/1 "2020-01-13T20:23:51Z")

</div>

How do we format an address that didn’t use the address input field to work correctly?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [January 13, 2020, 8:51pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/2 "2020-01-13T20:51:54Z")

</div>

You need to elaborate more with your question…

Where is this address input field that you are referring to?  
What code have you used so far on your page?  
Screenshots would be helpful too.

Is it in a user input form that you have created?  
If so then you can add a data hook to your code in the data.js file in your backend that alters the user inputs before they are saving into the dataset.  
[https://support.wix.com/en/article/corvid-about-data-hooks](https://support.wix.com/en/article/corvid-about-data-hooks)  
[https://support.wix.com/en/article/corvid-using-data-hooks](https://support.wix.com/en/article/corvid-using-data-hooks)  
[https://www.wix.com/corvid/reference/wix-data.Hooks.html](https://www.wix.com/corvid/reference/wix-data.Hooks.html)  
[https://www.wix.com/corvid/reference/wix-data.Hooks.html#beforeInsert](https://www.wix.com/corvid/reference/wix-data.Hooks.html#beforeInsert)  
Wix Corvid Tutorial:  
[https://support.wix.com/en/article/corvid-tutorial-processing-user-input-before-it-is-stored-in-a-collection-with-data-hooks](https://support.wix.com/en/article/corvid-tutorial-processing-user-input-before-it-is-stored-in-a-collection-with-data-hooks)

Or is it in the Wix Stores app?  
[https://www.wix.com/corvid/reference/wix-stores-backend.html#Address](https://www.wix.com/corvid/reference/wix-stores-backend.html#Address)

Or is it through the AddressInput that you use along with Google Maps?  
[https://www.wix.com/corvid/reference/$w.AddressInput.html](https://www.wix.com/corvid/reference/$w.AddressInput.html)

If you haven’t used any code on your page and you are just using the Wix Editor itself, then please put your issue through Wix Support instead.  
[https://support.wix.com/en/article/contacting-wix-support](https://support.wix.com/en/article/contacting-wix-support)

---

<div class="post-metadata">

**Author:** ![patrick](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/patrick/32/971_2.png) [@patrick](https://forum.wixstudio.com/u/patrick)\
**Post date:** [January 13, 2020, 9:56pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/3 "2020-01-13T21:56:58Z")

</div>

So its the address field type in the normal non wix app database itself. I have addresses all in the same format added to the database under the address type field. The addresses were not user input but from a csv of data I collected.

I am trying to figure out how to format the address to work with the database itself. When i go to the database there is a warning on those fields that the address is not correctly formatted and I can press the button to format it. I would prefer to bot have to press the button over 10k times.

In my admin page, I am able to update all of the addresses and they look like the ones from the address input but they still get the warning that its not correct format.

So like my original question states, what “format” do they need to be in to not get that warning and be able to work with google maps?

I know that the addresses gathered via address input are an Address object that has various information in such as formattedAddress etc. i didn’t know if there was a simple way to create a new address object that gets the rest of the info filled out.

---

<div class="post-metadata">

**Author:** ![marsan957](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@marsan957](https://forum.wixstudio.com/u/marsan957)\
**Post date:** [September 5, 2020, 2:25pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/4 "2020-09-05T14:25:49Z")

</div>

I have the sam problem, anyone that has the solution?

---

<div class="post-metadata">

**Author:** ![bwprado](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bwprado/32/7220_2.png) [@bwprado](https://forum.wixstudio.com/u/bwprado)\
**Post date:** [September 9, 2020, 11:47pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/5 "2020-09-09T23:47:01Z")

</div>

Same problem here using the Google Maps Geocoding API that returns the same formatted address as the Content Manager from Wix.

---

<div class="post-metadata">

**Author:** ![jetlaggedchef](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jetlaggedchef/32/23202_2.png) [@jetlaggedchef](https://forum.wixstudio.com/u/jetlaggedchef)\
**Post date:** [October 7, 2020, 12:43am UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/6 "2020-10-07T00:43:33Z")

</div>

Is this working for anyone yet? It looks like the Wix Address Input object linked to Google is creating a JSON string, but I can’t figure out how to save it to the “address” field in the Wix Contact list.

Do I have to decode this whole thing myself to save it?

(Also, it’s putting the “state” as “subdivision”)

city: “Orlando”  
​country: “US”  
​formatted: “3057 Tradeport Dr, Orlando, FL 32824, USA”  
​  
location: Object { latitude: 28.411084, longitude: -81.34604999999999 }  
​postalCode: “32824”  
​  
streetAddress: {…}  
​​name: “Tradeport Dr”  
​​number: “3057”  
​​  
: Object { … }  
​subdivision: “FL”

---

<div class="post-metadata">

**Author:** ![bwprado](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bwprado/32/7220_2.png) [@bwprado](https://forum.wixstudio.com/u/bwprado)\
**Post date:** [October 7, 2020, 11:49pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/7 "2020-10-07T23:49:23Z")

</div>

People, I solved it! I just haven’t got the time to post it here. Here is the thing, the Address Database Field is a JSON, so to save it to your dataset you need to format it as a JSON.

First I created an object as a container to format the address:

```javascript
function createNewAddressObject(obj) {
 let { address_components } = obj // extract the address_components property of the JSON
 let fullAddress = { // this is the JSON object that is going to be pushed to the database
        city: "",
        location: {
          latitude: obj.geometry.location.lat,
          longitude: obj.geometry.location.lng
        },
        streetAddress: {
          name: "",
          number: ""
        },
        formatted: obj.formatted_address,
        country: "",
        postalCode: "",
        subdivision: ""
    }
 for (const prop in address_components) {
 if (address_components.hasOwnProperty(prop)) {
 const element = address_components[prop];
 if (element.types.includes("administrative_area_level_2")) fullAddress.city = element.short_name
 else if (element.types.includes("route")) fullAddress.streetAddress.name = element.long_name
 else if (element.types.includes("postal_code")) fullAddress.postalCode = element.short_name
 else if (element.types.includes("administrative_area_level_1")) fullAddress.subdivision = element.short_name
 else if (element.types.includes("country")) fullAddress.country = element.short_name
 else if (element.types.includes("street_number")) fullAddress.streetAddress.number = element.short_name
        }
    }
 return fullAddress
}

```

And then I push the object fullAddress (as newAddressObject that I used as a variable to store the return from the function) to the dataset:

```javascript
async function createNewCostumerAndInsert() {
 let newCostumer = createNewCostumer(
        $w("#inputNewCostumerName").value,
        $w("#inputNewCostumerCPF").value,
        newAddressObject, // here it is.
        $w("#datePickerNewCostumerBday").value,
        $w("#inputNewCostumerAddComplement").value,
        $w("#inputNewCostumerEmail").value,
        $w('#inputCellphone').value
    )
    newCostumerId = await insertNewCostumer(newCostumer)
 if (newCostumerId) {
        $w('#textAlertNewCostumer').text = "Usuário inserido com sucesso!"
        $w('#textAlertNewCostumer').text.style.color = '#BADA55'
        $w('#textAlertNewCostumer').show()
        $w('#sectionNewCostumer').collapse()
        $w('#sectionNewOrder').expand()
        $w('#inputCostumer').value = newCostumer.name
    } else {
        console.log("Usuário não inserido!")
    }
}

```

---

<div class="post-metadata">

**Author:** ![jetlaggedchef](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jetlaggedchef/32/23202_2.png) [@jetlaggedchef](https://forum.wixstudio.com/u/jetlaggedchef)\
**Post date:** [October 8, 2020, 11:20am UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/8 "2020-10-08T11:20:46Z")

</div>

Thanks Bruno! When calling the createNewAddressObject() method, should I be passing in the actual AddressInput object from the form or the value?

createNewAddressObject( $w(‘#myAddressInput’) )

or

createNewAddressObject( $w(‘#myAddressInput’).value )

?

---

<div class="post-metadata">

**Author:** ![bwprado](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bwprado/32/7220_2.png) [@bwprado](https://forum.wixstudio.com/u/bwprado)\
**Post date:** [October 8, 2020, 6:45pm UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/9 "2020-10-08T18:45:01Z")

</div>

Hello Christopher, this function that I created is to format the JSON you get from the Google API.

Here is the backend call to the Google API:

```javascript
import { fetch } from 'wix-fetch'

const baseURL = "https://maps.googleapis.com/maps/api/geocode/json?"
const country = "BR"
const key = "your_API_key"

export function autocomplete(query) {
 let url = baseURL + "address=" + query + "&components=country:" + country + "&key=" + key
 return fetch(url, { method: 'get' }).then(httpResponse => {
 if (httpResponse.ok) {
 return httpResponse.json()
        }
    })
}

```

I call it through this command after any user input:

```javascript
let query = await autocomplete(val) // val being your $w('#myAddressInput').value

```

This query result is the Google JSON that you have to pass through the function to format it, otherwise the database will not accept it:

```javascript
let newAddressObject = createNewAddressObject(obj) // obj being the JSON, in this case you can use the query variable that was created. 

let newAddressObject = createNewAddressObject(query) // like this

```

If you have any doubt, just let me know.

---

<div class="post-metadata">

**Author:** ![lars-schaui](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lars-schaui](https://forum.wixstudio.com/u/lars-schaui)\
**Post date:** [April 28, 2022, 6:41am UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/10 "2022-04-28T06:41:26Z")

</div>

I do have the same problem as decribed by Patrick.  
As I am a beginner I don’t really understand the procedure/code described by Bruno.  
Is there no simple way, where I can format the address already in the correct way in my Excel/CSV file? This would make things a lot easier for me.  
Any help is highly appreciated.

---

<div class="post-metadata">

**Author:** ![bwprado](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bwprado/32/7220_2.png) [@bwprado](https://forum.wixstudio.com/u/bwprado)\
**Post date:** [April 28, 2022, 11:43am UTC](https://forum.wixstudio.com/t/address-database-field-type/29593/11 "2022-04-28T11:43:21Z")

</div>

Try saving the address in this format, inside your Excel file:

```javascript
{
  "city": "New York",
  "location": {
    "latitude": 40.7558611,
    "longitude": -73.987061
  },
  "streetAddress": {
    "number": "",
    "name": "",
    "apt": ""
  },
  "formatted": "New York, NY 10018, USA",
  "country": "US",
  "postalCode": "10018",
  "subdivision": "NY"
}

```
