Skip to content

Commit

Permalink
Merge pull request #227 from Arquisoft/fix-search
Browse files Browse the repository at this point in the history
fixed search bar
  • Loading branch information
oscar134 authored Apr 30, 2020
2 parents 3e5b97b + 5014fe2 commit fb44926
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/components/routeCreation/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,36 @@ class SearchBar extends React.Component {
} else {
toast.info(i18n.t("searching"));

search({ q: text }, function (err, opts, results) {
if (results.length > 0) {
let firstFound = results[0];

this.map.current.setState({ editablePosition: [firstFound.lat, firstFound.lon] });
this.map.current.setState({ boundingbox: firstFound.boundingBox });

this.search.current.value = firstFound.display_name;

toast.dismiss();
toast.success(i18n.t("mapCreationSearchBarFound") + firstFound.display_name);
fetch("https://nominatim.openstreetmap.org/search?q="+text+"&addressdetails=1&limit=3&format=json").then( (response) => {
if(response.status===200){
response.json().then( (results) => {
if (results.length > 0) {
let firstFound = results[0];

this.map.current.setState({ editablePosition: [firstFound.lat, firstFound.lon] });
this.map.current.setState({ boundingbox: firstFound.boundingBox });

this.search.current.value = firstFound.display_name;

toast.dismiss();
toast.success(i18n.t("mapCreationSearchBarFound") + firstFound.display_name);
}
else {
this.search.current.value = "";

toast.dismiss();
toast.error(i18n.t("mapCreationSearchBarError"));
}
});
}
else {
else{
this.search.current.value = "";

toast.dismiss();
toast.error(i18n.t("mapCreationSearchBarError"));
}

}.bind(this));
}
});
}
}

Expand Down

0 comments on commit fb44926

Please sign in to comment.