Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markers are jumping #1143

Open
pdwrl opened this issue Sep 7, 2022 · 55 comments
Open

Markers are jumping #1143

pdwrl opened this issue Sep 7, 2022 · 55 comments

Comments

@pdwrl
Copy link

pdwrl commented Sep 7, 2022

Hello.
Markers are jumping only when navigating the map by mouse's dran'n'drop. They appears on their old places for a short time and then showing on a right places.
Strange: It doesn't reproduces on Codesandbox.

Any ideas please?

maps.mp4
@itsmichaeldiego
Copy link
Member

@pdwrl Could you provide an example of your code, and which version of this library you're using?

@Exilent-aby
Copy link

Exilent-aby commented Sep 8, 2022

@pdwrl @itsmichaeldiego
I have forked @pdwrl 's codesandbox to use the new renderer for React 18. The markers can be seen jumping there.
Link to the fork
@pdwrl FYI: I changed the Index.js to this:

import React from "react";
import {createRoot} from "react-dom/client";
import SimpleMap from "./Map";
import { BrowserRouter, Link, Route } from "react-router-dom";
import "./styles.css";
const locations = require("./locations.json");

function App() {
  return (
    <div className="App">
      <SimpleMap locations={locations} />
    </div>
  );
}

const container = document.getElementById("root");
const rootElement = createRoot(container);
rootElement.render(<App/>);

@pdwrl
Copy link
Author

pdwrl commented Sep 8, 2022

@Exilent-aby yes, Your fork reproduces the jumping.
Thank You very much.

@pdwrl
Copy link
Author

pdwrl commented Sep 8, 2022

@itsmichaeldiego please, look at this sandbox
bug reproduces here.
thanks to @Exilent-aby

@EugeniaSSS
Copy link

EugeniaSSS commented Sep 8, 2022

@pdwrl, I have the same problem! SOS

@adrian-koczen
Copy link

I agree, It would be nice to make this work again 😀

@Exilent-aby
Copy link

@pdwrl For now, I have downgraded to react 17 to make it work for my case. Personally, I don't want to move away from this library, as I found this to be the most straightforward approach to implementing google maps in react so far.

@pdwrl
Copy link
Author

pdwrl commented Sep 9, 2022

downgraded to react 17

oh, I can't downgrade.
anyway, thank You so much.

@Exilent-aby
Copy link

This problem seems to be happening in many implementations of Google Maps with react. The official google map react wrapper (@googlemaps/react-wrapper) has this demo listed in their documentation on npmjs.com. But they too seem to be using ReactDom.render with react 18 to make it work, at least this is what the console shows.
Screenshot 2022-09-12 at 12 41 48 PM

We might have to wait a little longer for this issue to be fixed.

@kkallasm
Copy link

Same problem here. Any updates?

@JonasRothmann
Copy link

Same problem. We use React 18 in production and can't downgrade.

@mcgrealife
Copy link

A PR by @bordeo addresses this, but needs review and approval

@giorgiabosello
Copy link

@mcgrealife the PR of @bordeo address issues with react 18, but I've found out that something else happens:
markers are not being reinitialized, so, or you can't see them on the map, since they have wrong style positions, or they move with the map.
I have tried to fix it, but it's like a matrioska. I'm implementing maps with the official library (@googlemaps/react-wrapper) since I cannot downgrade to react 17 too.

@Eslam3bed
Copy link

Experiencing the same issue when upgraded to react 18 -_-

When I turn the StrictMode on the app crashes
juming_markers

@haabnaseem
Copy link

NextJS with React 18, same bug

@haabnaseem
Copy link

NextJS with React 18, same bug

@pdwrl can you make your lat, lng values are present? i had one marker which was missing lng value and when I fixed that markers didn't jump anymore.

@Eslam3bed
Copy link

@haabnaseem Can you explain more, these details are mandatory, we do provide them, however, we still face the same issue,
can you explain more about your findings?
Thanks

@ilan-belfer
Copy link

React 18. Same bug

googleMapReact18Bug.mp4

@mcgrealife
Copy link

@giorgiabosello ah I see.

The new google maps beta "Advanced Markers" look promising for most cases. I imagine these play well with the official @googlemaps/react-wrapper.

@giorgiabosello
Copy link

@mcgrealife at the end, I didn't use the official @googlemaps/reactwrapper, since it is only a wrapper that calls the API script. It doesn't accept markers as react components, but only the default one.
I've followed this guide.

@AndreiFVPopa
Copy link

AndreiFVPopa commented Oct 20, 2022

Hey there guys.
I've been struggling with this bug a lot also. It definitely needs a fix asap.
I temporarily found a workaround. I used an opacity state transition. With the help of drag and dragEnd, I managed to hide the dots while the flickering is happening.
const [opacity, setOpacity] = useState(1) ... <GoogleMapReact onDrag={() => setOpacity(0)} onDragEnd={() => setOpacity(1)} > <Marker style={{opacity: opacity}}>1</Marker> </GoogleMapReact>

@yakushstanislav
Copy link

Same problem.

1 similar comment
@xwg2015
Copy link

xwg2015 commented Oct 28, 2022

Same problem.

@Naught0
Copy link

Naught0 commented Nov 3, 2022

Any word on what's causing this? Why does reverting to react 17 fix it?

@giorgiabosello
Copy link

Any word on what's causing this? Why does reverting to react 17 fix it?

@Naught0 because React 18, in developer mode, mount and unmount the component to make some tests.

@Gigiz
Copy link

Gigiz commented Nov 11, 2022

Any word on what's causing this? Why does reverting to react 17 fix it?

@Naught0 because React 18, in developer mode, mount and unmount the component to make some tests.

Nope, i tried in production mode but this behaviour still present

@JavierSolis
Copy link

You can use the parameter onGoogleApiLoaded, to have the reference to the map and add the markers, these markers will not have the problem

. . . 
const renderPolylines =  (map, maps) => {
        //places is an object array with latitude and longitude
        places.map(place => {
            new maps.Marker({
                position: {
                    lat: place.lat,
                    lng: place.lng,
                },
                map,
            });})

        var bounds = new maps.LatLngBounds()
        for (let place of places) {
            bounds.extend(
                new maps.LatLng(place.lat, place.lng)
            )
        }
        map.fitBounds(bounds)
    }

. . .
<GoogleMapReact
                    bootstrapURLKeys={{key: "API_KEY"}}
                    defaultCenter={location}
                    defaultZoom={zoomLevel}
                    onGoogleApiLoaded={({map, maps}) => renderPolylines(map, maps)}>

. . .

@giorgiabosello
Copy link

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore.
LINK

@alehano
Copy link

alehano commented Nov 19, 2022

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore. LINK

Thanks, finally it's working

@sukhovv
Copy link

sukhovv commented Feb 28, 2023

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore. LINK

@giorgiabosello What about draggable markers in there? Looks like it is not supported in the same way with draggable + onChildMouseUp + onChildMouseMove props

@giorgiabosello
Copy link

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore. LINK

@giorgiabosello What about draggable markers in there? Looks like it is not supported in the same way with draggable + onChildMouseUp + onChildMouseMove props

Not managed, if you want to help with a PR, it's appreciated :)

@neo0910
Copy link

neo0910 commented Apr 11, 2023

@itsmichaeldiego

Hello, I have this problem on my project (React 18, google-map-react 2.2.0). Will the PR of bordeo be merged?

@giorgiabosello
Copy link

@neo0910 this PR fixes some things, but breaks some others.
If you don't need everything that's supported in this library, check Google Maps React Markers.

@Lamanris
Copy link

2023, the bug still exists

@Lamanris
Copy link

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore. LINK

Thank you!

@bradley-varol
Copy link

bradley-varol commented Apr 12, 2023

For anyone coming here, I highly recommend the repo linked above. We have fairly easily migrated with only some changes (e.g. onDragEnd had to be implemented manually):

  const onGoogleApiLoaded = ({ map }) => {
    mapRef.current = map
    mapRef.current.addListener('drag', onDrag)
    mapRef.current.addListener('dragend', onDragEnd)
  }

  <GoogleMapReact
          apiKey={apiKey}
          onGoogleApiLoaded={onGoogleApiLoaded}

and there's no reactive center prop so you have to call setCenter yourself:

  useEffect(() => {
    if (mapRef.current) {
      // set map location programmatically when the mapCenter var changes
      mapRef.current.setCenter(mapCenter)
    }
  }, [mapRef, dispatch, mapCenter])

@anabel29
Copy link

anabel29 commented May 5, 2023

Same issue :( any updates?

@ghost
Copy link

ghost commented May 16, 2023

Same Issue

@ghost
Copy link

ghost commented May 16, 2023

import React from 'react';
import ReactDOM from 'react-dom';
import { CssVarsProvider } from '@mui/joy/styles';
import { PersistGate } from 'redux-persist/integration/react';
import { Provider } from 'react-redux';
import { persistor, store } from 'tools/store';
import theme from 'tools/theme';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';
import './styles.css';

ReactDOM.render(
<React.StrictMode>



</React.StrictMode>,
document.getElementById('root')
);

use this in your index.tsx/js it will act as react 17 and fix this bug

@sukhovv
Copy link

sukhovv commented May 31, 2023

@itsmichaeldiego great to know the library is still alive.
any chance this issue will be fixed?

@tvNitesh
Copy link

same Issue :( , any update ?

wpwilson10 added a commit to wpwilson10/PatrickWilsonSite that referenced this issue Jun 3, 2023
render map and marker.

Note issue where marker moves around on rerenders: google-map-react/google-map-react#1143
@Mu-Aleem
Copy link

Mu-Aleem commented Jun 4, 2023

same issue when i drap the map my current location marker moves. how can i fix this i,m using the react 18 and google-map-react

@giorgiabosello
Copy link

Guys, there isn't a fix for this issue. It is how React18 works on developer mode.
You shouldn't have problems in production mode.
This library needs to be completely rewritten to work with R18+, I tried to to fix it but it was like a matrioska problem, so I coded from zero a library.
Google Maps React Markers

@Mu-Aleem
Copy link

Mu-Aleem commented Jun 4, 2023

Guys, there isn't a fix for this issue. It is how React18 works on developer mode. You shouldn't have problems in production mode. This library needs to be completely rewritten to work with R18+, I tried to to fix it but it was like a matrioska problem, so I coded from zero a library. Google Maps React Markers

what do you suggest? I want to add the map the same as Uber.

@giorgiabosello
Copy link

giorgiabosello commented Jun 4, 2023

Guys, there isn't a fix for this issue. It is how React18 works on developer mode. You shouldn't have problems in production mode. This library needs to be completely rewritten to work with R18+, I tried to to fix it but it was like a matrioska problem, so I coded from zero a library. Google Maps React Markers

what do you suggest? I want to add the map the same as Uber.

@Mu-Aleem there isn't much you can do:

  • keep this library and use it only on production mode
  • code from zero another one, using Google Maps API
  • use mine (mentioned above) and integrate with a PR what you think is missing and should be available to everyone.

@rise2vados
Copy link

Guys, there isn't a fix for this issue. It is how React18 works on developer mode. You shouldn't have problems in production mode. This library needs to be completely rewritten to work with R18+, I tried to to fix it but it was like a matrioska problem, so I coded from zero a library. Google Maps React Markers

giorgiabosello, first of all, thank you for using google-maps-react-markers. Everything works well without any jumps or flickers, but I have a need to change the center of the map after clicking on a marker. How can I achieve this? Thank you once again.

@giorgiabosello
Copy link

@rise2vados this isn't the right thread. There's a discussion in the repository asking the same thing. Check there and you'll find your answer. :)

@yusufkhaled-DC
Copy link

I've made a repository myself which is working with React 18. I've abandoned this one, since it seems it is not maintained anymore. LINK

You're amazing!!! Thank you so much

@hoangviet1807
Copy link

Any updates???

@HelloNeptune
Copy link

HelloNeptune commented Dec 5, 2023

Any updates???

#1197 (comment) this may help, give a try

@karimtamerBW
Copy link

Any new updates please?

@stevengrimaldo
Copy link

still an issue 2024 even though their last release says supporting react 18, so i dont think react 18 had anything to do with it maybe @giorgiabosello.

@giorgiabosello
Copy link

still an issue 2024 even though their last release says supporting react 18, so i dont think react 18 had anything to do with it maybe @giorgiabosello.

Yes, it does! Because it mounts and remounts the components, and the library doesn't work. It's old.

@stevengrimaldo
Copy link

still an issue 2024 even though their last release says supporting react 18, so i dont think react 18 had anything to do with it maybe @giorgiabosello.

Yes, it does! Because it mounts and remounts the components, and the library doesn't work. It's old.

the library is old yes, the library works but still has the jumpiness as you mentioned.

@Hosar
Copy link

Hosar commented Apr 23, 2024

2024, and still the same problem 🫠
Thanks @giorgiabosello for your solution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests