Open Ashwin7mak opened 4 years ago
thank you
That happens when country resets to worldwide, there's no corresponding lat and long coming from data. I tried to solved with this.
if (countryCode === "worldwide") {
setMapCenter([34.80746, -40.4796]);
setMapZoom(2);
} else {
setMapCenter([data.countryInfo.lat, data.countryInfo.long]);
setMapZoom(4);
}
Отправлено из myMail для Android пятница, 04 сентября 2020г., 13:11 +02:00 от Arkar Min Tun notifications@github.com :
That happens when country resets to worldwide, there's no corresponding lat and long coming from data. I tried to solved with this. if (countryCode === "worldwide") { setMapCenter([34.80746, -40.4796]); setMapZoom(2); } else { setMapCenter([data.countryInfo.lat, data.countryInfo.long]); setMapZoom(4); }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub , or unsubscribe .
if (countryCode === "worldwide") { setMapCenter([34.80746, -40.4796]); setMapZoom(2); } else { setMapCenter([data.countryInfo.lat, data.countryInfo.long]); setMapZoom(4); }
i was also try this ,but it is not working , it show error.
× Unhandled Rejection (TypeError): Cannot read property 'lat' of undefined (anonymous function) G:/Covid-Tracker/covid19/src/App.js:77 74 | setMapCenter([34.80746, -40.4796]); 75 | setMapZoom(2); 76 | } else {
77 | setMapCenter([data.countryInfo.lat, data.countryInfo.long]); | ^ 78 | setMapZoom(4); 79 | } 80 | View compiled async onCountryChange G:/Covid-Tracker/covid19/src/App.js:67 64 | countryCode === "worldwide" 65 | ? "https://disease.sh/v3/covid-19/all" 66 | :
https://disease.sh/v3/covid-19/countries/${countryCode}
; 67 | await fetch(url) 68 | .then((response) => response.json()) 69 | .then((data) => { 70 | setCountry(countryCode);
please help me ,
Use this setMapCenter(countryCode ==="worldwide" ? {lat: 34.80746, lng: -40.4796} : [data.countryInfo.lat, data.countryInfo.long]); setMapZoom(countryCode === "worldwide" ? 2.5 : 4);
inside const onCountryChange
In the dropdown, when we try selecting some country, map is centering to the country's coordinates. But when we try selecting the worldwide option in the dropdown, map is struck when trying to get back to the original state.
There is also an error in the console. Check the attachment for the screenshot.