You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fitbounds and directionService is not updating markers on the map #1206
When i click a marker to create direction route, markers are not updating properly. We are using react 18.2.0 but same codes are working like a charm on react 16.13.1. I don't understand what is the problem.
Screen.Recording.2023-12-25.at.18-58-29.mp4
functiononMarkerClick(lat,lng,markerId){setActiveMarkerId(markerId);setPath(null);if(route)route.setMap(null);if(map&&maps){constdirectionsService=newmaps.DirectionsService();constdirectionsDisplay=newmaps.DirectionsRenderer();directionsService.route({origin: newmaps.LatLng(projectLocation.lat,projectLocation.lng),destination: newmaps.LatLng(lat,lng),travelMode: 'DRIVING'},(response,status)=>{if(status==='OK'){directionsDisplay.setDirections(response);setRoute(newmaps.Polyline({path: [],geodesic : true,strokeColor: getComputedStyle(document.documentElement).getPropertyValue('--map-route-color').trim(),strokeOpacity: 1.0,strokeWeight: 5,editable: false,map: map}));setPath(response.routes[0].overview_path);setDistance(parseFloat((response.routes[0].legs[0].distance.value/1000)).toFixed(1))setDuration(parseInt((response.routes[0].legs[0].duration.value/60)).toFixed(0))}else{window.alert('Directions request failed due to '+status);}});varbounds=newmaps.LatLngBounds();bounds.extend(newmaps.LatLng(projectLocation.lat,projectLocation.lng));bounds.extend(newmaps.LatLng(lat,lng));letpadding=window.innerWidth*0.1;map.fitBounds(bounds,padding);}}
Activity
The-Code-Monkey commentedon Feb 6, 2024
Im coming up with this same issue, it used to work, i know this because i am rebuilding a site.