Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.
@scottagarman
Copy link

scottagarman commented Jul 21, 2020

right now w/o google geocoding we send this which does NOT work on onfleet
address: { unparsed: '1738 Haight Street 407, 94117, USA' }

adding in apartment still fails when including 'street2' in unprased as currently do
address: { unparsed: '1738 Haight Street 407, 94117, USA', apartment: '407' }

works without unit prefix:
address: { unparsed: '1738 Haight Street, 94117, USA', apartment: '407' }

works with unit prefix:
address: { unparsed: '1738 Haight Street, 94117, USA', apartment: 'Unit 407' }

adding "Unit" in front of street2 task still gets created and links to gmaps ok but you can get cases like this:
1738 Haight Street
Unit Unit 407
San Francisco, California 94117

notes:
The "Unit" seems optional and we should get clarity on why and when we should hard code that.

current issues/questions:
- what's the status of google.parseAddress? I didn't test any results from that yet, don't have a key.
- we use 'street2' as apartment. Are there other cases where someone (or google???) will return something for street2 that SHOULD NOT go into onfleet's 'apartment'?
- will pulling our 'street1' + ' ' + 'street2' out of unparsed break other addresses?



@scottagarman
Copy link

when using google parsedAddress we send
  address: {
    number: '1738',
    street: 'Haight Street',
    apartment: '407',
    city: 'San Francisco',
    state: 'California',
    postalCode: '94117',
    country: 'US'
  }

which works fine. not sending parsed address here

@jwickens
Copy link

jwickens commented Oct 6, 2021

Here's what happens when we use the Graves Ave. example today:

{
  body: { unparsed: '8729 Graves Avenue 7B, 92071, USA' },
  response: {
    id: 'GvFpkX5ybjTbFpI1dtzG43XN',
    timeCreated: 1633538363000,
    timeLastModified: 1633538363485,
    location: [ -116.9608202, 32.8341889 ],
    address: {
      apartment: '',
      state: 'California',
      postalCode: '92071',
      number: '8729',
      street: 'Graves Avenue',
      city: 'Santee',
      country: 'United States'
    },
    notes: '',
    metadata: [],
    googlePlaceId: 'Eio4NzI5IEdyYXZlcyBBdmUgIzdiLCBTYW50ZWUsIENBIDkyMDcxLCBVU0EiHhocChYKFAoSCfMkgFltWNmAES2Axv89HhLCEgI3Yg',
    warnings: []
  }
}

In this case apartment is not being included in the Onfleet Response.

When I deploy the changes in https://github.com/meadow/api/pull/1232 and do the same logging I get

{
  body: { unparsed: '8729 Graves Avenue, 92071, USA', apartment: '7B' },
  response: {
    id: 'js5p3OYJHCvLPNlJb1EOR9I3',
    timeCreated: 1633538530000,
    timeLastModified: 1633538530097,
    location: [ -116.9608202, 32.8341889 ],
    address: {
      apartment: '7B',
      state: 'California',
      postalCode: '92071',
      number: '8729',
      street: 'Graves Avenue',
      city: 'Santee',
      country: 'United States'
    },
    notes: '',
    metadata: [],
    googlePlaceId: 'ChIJ8ySAWW1Y2YARLYDG_z0eEsI',
    warnings: []
  }
}

@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