Fix: if center changed before google map api was finished, map center will keep as the previous center by sspku-yqLiu · Pull Request #1205 · google-map-react/google-map-react

hi Google map react team.

We faced an issue during use google map react. If api from https://maps.googleapis.com is very slow, and we change map center before google map api return data. map may cannot detect the center change and will not move the center to the correct place.

Steps to reproduce:

  • use Default center, lets say center of singapore as the fallback location of my address
  • fetch data from https://maps.googleapis.com and https://www.getMyHomeAddress.com
  • https://www.getMyHomeAddress.com return value first
  • change the pin and center value to the api data. and for now, we cannot find this.map_, which mean we will skip the panTo function
  • https://www.getMyHomeAddress.com return value
  • since the prevProps center is already changed to my home, so it wont trigger panTo function also
  • google map will show the center as the fall back address

Plans for solve the problem:

  • add a state initializedCenter_ to force trigger panTo function when map is shown