You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using NearbySearch in Google Maps API Places library to get the primary schools of different locations nearby. I get the results successfully but the problem is every time when I enter other pages of other listings(different locations), the search result of the primary schools is the previous one, I have to refresh the page manually, then the new search result will come out. Does anyone know how to re-render the search result automatically based on the different locations? Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi All,
I am using NearbySearch in Google Maps API Places library to get the primary schools of different locations nearby. I get the results successfully but the problem is every time when I enter other pages of other listings(different locations), the search result of the primary schools is the previous one, I have to refresh the page manually, then the new search result will come out. Does anyone know how to re-render the search result automatically based on the different locations? Thanks!
#map.jsx:
......
const { isLoaded } = useLoadScript({
googleMapsApiKey: process.env.REACT_APP_GEOCODE_API_KEY,
libraries,
});
const onMapLoad = (map) => {
let request = {
location: { lat, lng },
radius: "1000",
type: ["primary_school"],
};
service = new window.google.maps.places.PlacesService(map);
service.nearbySearch(request, (results, status) => {
if (status === window.google.maps.places.PlacesServiceStatus.OK) {
console.log(results);
let schools = [];
for (var i = 0; i < results.length; i++) {
const school = results[i].name;
schools.push(school);
}
setSchool(schools);
}});};
return (
Primary schools nearby
{school.map((s) => ({s}
))}Beta Was this translation helpful? Give feedback.
All reactions