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

the custom marker change position whenever i zoom or drag the map #1193

Open
george-steven0 opened this issue Jul 16, 2023 · 21 comments
Open

Comments

@george-steven0
Copy link

george-steven0 commented Jul 16, 2023

here is the code i'm using i dont know if there is something wrong i'm doing here but everything is rendered and works fine except the markers they keep change position when drag the map to any direction or when zoom in/out the map

here is the code i'm using below.

import GoogleMapReact from 'google-map-react';
import GoogleMap from 'google-map-react';
import { HiOutlineLocationMarker } from 'react-icons/hi';
import { useCallback, useEffect, useState } from 'react';

const MapMarker = ({ lat,lng, text }) => {
const greatPlaceStyle = {
position: 'absolute',
transform: 'translate(-50%, -50%)'
}

return(
  <div style={{...greatPlaceStyle, top : lat, left:lng }}>{text}</div>
)

}

const MapComponent = () => {
const path = [{ lat: 30.0444, lng: 31.2357 }, { lat: 30.2001, lng: 29.9187 }]

const mapOptions = {
    center: { lat: 30.0444, lng: 31.2357 },
    zoom: 7,
    language : 'en',
    zoomControl: true,
    fullscreenControl: true,
    mapTypeControl: true,
    streetViewControl: true,
};

const handleApiLoaded = (map, maps) => {
    const line = new maps.Polyline({
        path: path,
        geodesic: true,
        strokeColor: '#3454b6',
        strokeOpacity: 1.0,
        strokeWeight: 6,
    });

    line.setMap(map);
};


return ( 
    <>
        <GoogleMapReact
            bootstrapURLKeys={{ key: "",v: '3.31'  }}
            defaultCenter={mapOptions.center}
            defaultZoom={mapOptions.zoom}
            yesIWantToUseGoogleMapApiInternals
            onGoogleApiLoaded={({ map, maps }) => handleApiLoaded(map, maps)}
        >

        {path?.map( (item,index)=>(
            <MapMarker
                key={index}
                lat={item.lat}
                lng={item.lng}
                text={<HiOutlineLocationMarker className="text-3xl text-mainRed" />}
            /> 
        ) )}
           
    </>
 );

}

export default MapComponent;

@sumankalia
Copy link

facing the same issue as well

@dorakadri
Copy link

dorakadri commented Jul 16, 2023

same ,and just an advice remove ur key from the post ihope the creator respond i've been trying to make it work 1week now all my project depend on this

@george-steven0
Copy link
Author

same ,and just an advice remove ur key from the post ihope the creator respond i've been trying to make it work 1week now all my project depend on this

Thank you for your advice I did remove the key

@dorakadri
Copy link

did you find a solution ?

@mertcankose
Copy link

I have a same problem my custom marker change position when i zoom in and zoom out.

@dorakadri
Copy link

i think its a problem in the library cause look their is somehow a div that the marker is on and it moves the marker with it i hope they fix it or atleast they respond us the tranform position absolute dont work either
image

@george-steven0
Copy link
Author

did you find a solution ?

No not yet, unfortunately

@dorakadri
Copy link

i switched to this library at it works perfectly google-maps-react-markers

@ahsuniqbal
Copy link

Facing the same issue, did anyone find any solution?

@mainrs
Copy link

mainrs commented Jul 30, 2023

@george-steven0 your key is still there. You have to click on the "edited" button and delete the old entry. At this point your key is compromised. You should just generate a new one and discard this one.

@unimonkiez
Copy link

I have that issue too! Will probably do @dorakadri if no solution is found

@DeepanshuRKM
Copy link

I am also facing the same issue. @dorakadri could you please debug the library as per required?

@dorakadri
Copy link

the library allow u to display ur marker as component here an exemple : <GoogleMap
apiKey={}
onGoogleApiLoaded={onGoogleApiLoaded}
defaultZoom={14}
center={{ lat: Number(coords?.lat), lng: Number(coords?.lng) }}
defaultCenter={{ lat: Number(coords?.lat), lng: Number(coords?.lng) }}
options={{
streetViewControl: true,
fullscreenControl: true,
disableDefaultUI: true,
zoomControl: true,
styles: mapStyles,
}}
>


pulse its a normal react component you just need to add the lat and lng and u dont need to receive it as props in the component

@DeepanshuRKM
Copy link

DeepanshuRKM commented Aug 10, 2023

@dorakadri Yes, we are able to display the marker but the issue remains. Issue still remains. It makes more bad impact on phones when users pinch in or out of the map. Could you please do the needful in the library or suggest any change?

@dorakadri
Copy link

I completely changed the library its not this one its another one forget about this one

@ElsaMarziano
Copy link

Is there an update on the subject? I'm facing the same problem

@AliasPedroKarim
Copy link

Me too !!

@AEidSPL
Copy link

AEidSPL commented Oct 22, 2023

try this to marker div :
style={{
position: "absolute",
top: "100%",
left: "50%",
height: "24px",
width: "24px",
transform: "translate(-50%, -100%)",
}}

@Anjana-lakshan
Copy link

Is there an update on that topic?

@ElsaMarziano
Copy link

I ended up using another library - google-maps-react-marker. It's doing pretty much the same job and worked fine for me

@CharlieGroves
Copy link

try this to marker div : style={{ position: "absolute", top: "100%", left: "50%", height: "24px", width: "24px", transform: "translate(-50%, -100%)", }}

@AEidSPL worked for me! thanks

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