Plans to improve API response
See original GitHub issueHi,
In the past few weeks I had to implement this but for React Native, so I ended up doing mostly the same you are doing here…
All good, until they made me notice that results are not displayed the same as in the demo in https://community.algolia.com/places. After expending some time having a look to the code, I found this file, and I was really surprised about all the parsing you are doing to what comes in the response.
I was wondering if there is a plan to improve the API in a way that there would be no need to do so, and also improve its structure, since now it’s very hard to get what some fields means…
This is what I’m doing now
import _isEqual from 'lodash/isEqual';
const getName = ({locale_names}) =>
locale_names[0].replace('<streetnum>', '');
const getFirst = array => array && array[0];
const getCity = ({city, county}) =>
getFirst(city)
|| getFirst(county);
const getPlace = result => ({
city: getCity(result),
countryCode: result.country_code,
name: getName(result),
postalCode: result.postcode[0],
state: result.administrative && result.administrative[0],
});
const getCoordinate = ({_geoloc}) => ({
latitude: _geoloc.lat,
longitude: _geoloc.lng,
});
const areLocationsEqual = (l1, l2) =>
l1 && l2
&& _isEqual(l1.coordinate, l2.coordinate)
&& _isEqual(l1.place, l2.place);
const toLocation = (result, currentLocation) => {
const location = {
coordinate: getCoordinate(result),
place: getPlace(result),
};
location.isCurrent = areLocationsEqual(location, currentLocation);
return location;
};
const manyToLocation = (results, currentLocation) => results.map(
curResult => toLocation(
curResult,
currentLocation
)
);
export default manyToLocation;
In some parts we are doing the same, but in others now that I have seen what you are doing, well, I guess I misunderstood some names and I ended up with a couple of differences…
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (8 by maintainers)
Top GitHub Comments
@vvo @Nagriar This is actually a simple typo bug. There’s a mismatch between what’s being pushed to
bestAttributes
(index and matchedWords) and what’s being used for each item in the array (index and words).You have
and
lines for reference:
Either change matchedWords to words, or the opposite and that should solve the first issue @mgtitimoli is talking about. (The sort currently does nothing)
Sorry for the late reply, this was fixed in #435