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
Component/Marker always re-center after map interaction #1189
Comments
I'm having the same issue: Spent hours trying to figure out why this doesn't work. Any markers place on the map do drag when the map is moved or zoomed, but soon as the action stops, the marker components reposition themselves at their initial position (that is, relative to viewport, rather than relative to the map). const styleMap={
display: "block",
position: "relative",
marginTop: "2rem",
width: "100%",
height: "90vh",
overflow: "hidden",
}
const pinStyle = {
}
const LocationPin = ({ text }) => (
<div style={ pinStyle }>
<PushPinOutlinedIcon />
<p className="">{text}</p>
</div>
)
export default function MapView() {
const [locations, setLocations] = useState([]);
const [isLoaded, setIsLoaded] = useState(false);
const q = query(collection(db, "locations"));
const getLocations = async () => {
const querySnapshot = await getDocs(q);
const l = [];
querySnapshot.forEach((doc) => {
l.push({
...doc.data(),
id: doc.id
});
});
console.log("ESFF: loaded locations", l);
setLocations(l);
setIsLoaded(true)
}
useEffect(() => {
getLocations();
}, [])
const defaultLocation = {
center: {
lat: 55.9579741,
lng: -3.1966372,
},
zoom: 13
}
return (
<>
{ isLoaded &&
<Box style={styleMap}>
<GoogleMapReact
bootstrapURLKeys={{ key: import.meta.env.VITE_GOOGLEMAPS_API_KEY }}
yesIWantToUseGoogleMapApiInternals
defaultCenter={defaultLocation.center}
defaultZoom={defaultLocation.zoom}>
{locations.map((place) => (
<LocationPin
key={place.id}
text={place.title}
lat={parseFloat(place.lat)}
lng={parseFloat(place.lng)}
/>
))}
</GoogleMapReact>
</Box>
}
</>
) |
Update: I notice further back in the issues someone posted a link to their fork. It has almost identical functionality, but doesn't appear to suffer the issue described above: |
Thanks! Switched to https://github.com/giorgiabosello/google-maps-react-markers and it worked well for me so far! |
Any updates/fixes? |
any fixes? |
Same issue |
Facing same issue |
Same issue. Follwing... |
Use the forked project mentioned above. That works. |
@shellbryson @tao-qian @jarlnartey @Fullbusters @thinhnuine I have face the same issue and debugged literally 8+ hrs , And finally I found out just remove restrictmode from index.js in react From :-
|
A word of caution: Strict mode is there for a reason and disabling it not a risk worth taking in a production app, in my opinion. |
Any update? Following... |
True , This is a major issue , But this repo is not active now. |
The best solution here is to switch to the best map library - Mapbox. However, if you're forced to use google maps like me - the only option is to use their official react-wrapper library and forget about declarative React API |
This was my solution: https://github.com/giorgiabosello/google-maps-react-markers |
I have this with Next.js in dev mode. When I build the app and run the production build, it works fine. Maybe it has to do with some reload mechanism that is employed only in dev mode. |
This seems to have solved my issue. It appears to be related to hot reloading in NextJs. |
I solved this issue in Index.js. import ReactDom from "react-dom" instead of "react-dom/client" |
This does not work in development because of the React.StrictMode, but when you build it works good. At least for me. |
Hi! It seems like the custom React component drawn on the map is always centered on the map (instead of being pinned to a particular location on the map and moving with the map), even when I change the map view through dragging/zooming.
This is not reproducible in the JS Bin examples, but I after I copy the same code to a local project (freshly created with create-react-app), it would be reproducible.
Here is a code snippet I used for testing:
To Reproduce 🔍
Steps to reproduce the behavior:
npm install google-map-react --save
Expected behavior 💭
The "MyPlace" marker should move with the map view.
Screenshots 🖥
If applicable, add screenshots to help explain your problem.
Environment:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: