Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Fauntleroy/b2fb4cc12a93805b942bfb7d306e7790 to your computer and use it in GitHub Desktop.
Save Fauntleroy/b2fb4cc12a93805b942bfb7d306e7790 to your computer and use it in GitHub Desktop.
Onfleet Google Geocoding Doc
Problem
Due new requirements from Google Geocoding API guideline, they are categorizing strictness on the apartment/office buildings.
They are now qualified as GEOMETRIC_CENTER. However, due to their own guideline, we can’t accept geometric_center as a valid address.
There is some situation with our system that we are in the process of changing but not quite there.
Depending on how the address field is sent in. We can tackle this problem using my workaround for now.
Here’s a valid address that would used to work:
{
"address": {
"unparsed": "8729 Graves Ave, Santee, CA, 92071"
}
}
or
{
"address": {
"apartment": "7B",
"unparsed": "8729 Graves Ave, Santee, CA, 92071"
}
}
But now it will give us an error:
{
"code": "InvalidContent",
"message": {
"error": 1000,
"message": "The values of one or more parameters are invalid.",
"cause": "Geocoding errors found.",
"request": "d5e0981e-4231-4cee-9021-aa0108009517",
"remoteAddress": "104.248.209.194"
}
}
Proposed solution:
Add “apartment” into the unparsed address:
{
"address": {
"apartment": "Unit <unit_here>",
"unparsed": "<street_number> <street_name>, Unit <unit_number_here>, <city>, <state>, <zip_code>, <country>"
}
}
Using above address as an example:
{
"address": {
"apartment": "7B",
"unparsed": "8729 Graves Ave, 7B, Santee, CA, 92071"
}
}
Would give us:
{
"id": "qTsztBhZXnZuoSCwMFAdpsxy",
"timeCreated": 1595289745000,
"timeLastModified": 1595289745736,
"location": [
-116.9608389,
32.8341528
],
"address": {
"apartment": "7B",
"state": "California",
"postalCode": "92071",
"number": "8729",
"street": "Graves Avenue",
"city": "Santee",
"country": "United States"
},
"notes": "",
"metadata": []
}
Future consideration
Ideally we would like to have each individual address cached, that’s why we keep geocoding records on our end and have a destination endpoint. If you have some sort of cache that you can utilize when making these requests. The new workflow would be
Make a destination
Get the destination ID from Onfleet
Ask the users to verify again if the address is correct.
Cache locally with the user’s info
And when everything is good, make the destination with the destination ID instead of keep sending a new unparsed address each time.
@jwickens
Copy link

jwickens commented Oct 6, 2021

Here's what happens with the new example that came up (Onfleet support emails Sept. 15 2021)

Current code:

{
  body: { unparsed: '651 North El Camino Real 203, 94402, USA' },
  response: {
    id: 'KTiaf90j7F8ZJzpKOokG07B4',
    timeCreated: 1633539576000,
    timeLastModified: 1633539576038,
    location: [ -122.3262571, 37.5633699 ],
    address: {
      apartment: '',
      state: 'California',
      postalCode: '94401',
      number: '203',
      street: 'North El Camino Real',
      city: 'San Mateo',
      country: 'United States'
    },
    notes: '',
    metadata: [],
    googlePlaceId: 'Ei4yMDMgTiBFbCBDYW1pbm8gUmVhbCwgU2FuIE1hdGVvLCBDQSA5NDQwMSwgVVNBIhsSGQoUChIJ72tZlnGej4ARUpkNwSVvY4UQywE',
    warnings: [ 'MISMATCH_NUMBER' ]
  }
}

https://github.com/meadow/api/pull/1232 :

{
  body: {
    unparsed: '651 North El Camino Real, 94402, USA',
    apartment: '203'
  },
  response: {
    id: 'JjKpdoEQoMYu3BcDSRbJC8ti',
    timeCreated: 1633539510000,
    timeLastModified: 1633539510980,
    location: [ -122.3406876, 37.5729768 ],
    address: {
      apartment: '203',
      state: 'California',
      postalCode: '94401',
      number: '651',
      street: 'North El Camino Real',
      city: 'San Mateo',
      country: 'United States'
    },
    notes: '',
    metadata: [],
    googlePlaceId: 'ChIJF8UwauSdj4ARTNcEjf4CcH4',
    warnings: [ 'GEOMETRIC_CENTER' ]
  }
}

The definition of these warnings can be found here: https://docs.onfleet.com/reference#destination-address-warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment