Converting current pixels into coordinates based on current position #434
Closed
teengineer
started this conversation in
General
Replies: 1 comment 2 replies
-
May I ask where those prediction-objects are coming from? And what coordinate system are they specified in? Is that a position within the map-div? It seems very weird to me to receive something like that, but not the geo-coordinates along with it. Whatever that may be, I see basically two ways to do something like that:
const map = useMap();
const [projection, setProjection] = useState<google.maps.MapCanvasProjection>();
useEffect(() => {
if (!map) return;
const overlay = new google.map.OverlayView();
// not sure if these two have to be provided, maybe works fine without them..
overlay.onAdd = () => {};
overlay.onRemove = () => {};
overlay.draw = () => {
// I'm assuming this will always return the same projection instance, might not be the case...
const proj = overlay.getProjection();
if (proj !== projection) setProjection(proj);
};
overlay.setMap(map);
return () => {
overlay.setMap(null);
setOverlay(null);
}
}, [map]);
useEffect(() => {
if (!projection) return;
// now you have the projection interface available and can use e.g. [`projection.fromDivPixelToLatLng()`](https://developers.google.com/maps/documentation/javascript/reference/overlay-view#MapCanvasProjection.fromDivPixelToLatLng)
}, [projection]); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have some pixels and i want to convert these to coordinates but when i use map.getProjection().fromPointToLatLng() func. , it convert to coordinates based on all google maps image not current position, how can i convert this pixels to coordinates based on current map position?
Beta Was this translation helpful? Give feedback.
All reactions