CleverProgrammers / react-covid-tracker

202 stars 252 forks source link

Map is not navigating back to its coordinates on choosing worldwide option in the dropdown #1

Open Ashwin7mak opened 4 years ago

Ashwin7mak commented 4 years ago

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.

Screen Shot 2020-08-02 at 5 29 33 PM
alex197925 commented 4 years ago

thank you

arkarmintun1 commented 4 years ago

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);
}
alex197925 commented 4 years ago

Thank you.I will check

Отправлено из 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 .

yogesh0037 commented 4 years ago

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 ,

rajeshpoojari39 commented 4 years ago

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