radarlabs / radar-sdk-js

Web JavaScript SDK for Radar, the leading geofencing and location tracking platform
https://radar.com
Apache License 2.0
41 stars 11 forks source link

Autocomplete and Forward Geocoding returning different values #164

Open mattstrick opened 2 months ago

mattstrick commented 2 months ago

Hi,

When I use the Autocomplete SDK I get different results for the same location than when I use the Forward Geocoding SDK.

Autocomplete Implementation Radar.ui.autocomplete({ container: container, responsive: true, width: "600px", onSelection: (result) => { setFormattedAddress(result.formattedAddress); setLayer(result.layer); setState(result.state); setCity(result.city); setCounty(result.county); setNeighborhood(result.neighborhood); setCountry(result.country); }, minCharacters: 3, placeholder: "Search address", countryCode: "US,CA", expandUnits: true, });

Autocomplete Response { "addressLabel": "3836 N Racine Ave", "number": "3836", "street": "N Racine Ave", "city": "Chicago", "stateCode": "IL", "postalCode": "60613", "county": "Cook", "countryCode": "US", "formattedAddress": "3836 N Racine Ave, Chicago, IL 60613 US", "layer": "address", "latitude": 41.952192, "longitude": -87.6595612, "geometry": { "type": "Point", "coordinates": [ -87.6595612, 41.952192 ] }, "distance": 66796.83975361186, "confidence": "exact", "state": "Illinois", "country": "United States", "countryFlag": "🇺🇸" },

Forward Geocoding Implementation Radar.forwardGeocode({ query: slug }) .then((result) => { const { addresses } = result; setAddressObject({ state: addresses[0].state as string, county: addresses[0].county as string, city: addresses[0].city as string, neighborhood: addresses[0].neighborhood as string, country: addresses[0].country as string, }); }) .catch((err) => { // handle error from Radar setAddressObject({ state: "", county: "", city: "", neighborhood: "", country: "", }); });

Forward Geocoding Response { "latitude": 41.952192, "longitude": -87.659561, "geometry": { "type": "Point", "coordinates": [ -87.659561, 41.952192 ] }, "country": "United States", "countryCode": "US", "countryFlag": "🇺🇸", "county": "Cook County", "distance": 66851, "confidence": "exact", "borough": "North Side", "city": "Chicago", "number": "3836", "neighborhood": "Lakeview", "postalCode": "60613", "stateCode": "IL", "state": "Illinois", "street": "N Racine Ave", "layer": "address", "formattedAddress": "3836 N Racine Ave, North Side, Chicago, IL 60613 USA", "addressLabel": "3836 N Racine Ave" }

Notice that in the Autocomplete Response, county comes back as Cook, and there is no neighborhood attribute. On the Forward Geocoding Response, county comes back as Cook County and there is a neighborhood attribute. I need to have the same data returned for the county attribute, and would also like to get access to the neighborhood attribute on the autocomplete response.