How to create a blue dot location marker? #552
-
Hello. I am pretty new to react and react libraries, as the question states I would like to add/create the blue dot user location marker for my map(with the accuracy radius as well). would appreciate any help I read and went through a bunch of guides but they don't seem to work with this library. I keep getting error: google.map.symbolPath.Circle is undefined |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
That isn't supported out-of-the box in this library, but we published an implementation of this using just the google maps API here: https://github.com/ubilabs/geolocation-deviceorientation-demo Most interesting bits for you would probably be the Now, if you want to use this in React, you could copy those files and create a wrapper component for the import {GeolocationMarker} from '...';
import {useMap} from '@vis.gl/react-google-maps';
const GeolocationMarker = (props) => {
const {position, size, heading, accuracy} = props;
const map = useMap();
// create geolocation-marker once api is ready
const geolocationMarker: GeolocationMarker | null = useMemo(
() => map ? new GeolocationMarker() : null,
[map]
);
// add/remove marker to/from map
useEffect(() => {
if(!geolocationMarker) return;
geolocationMarker.setMap(map);
return () => geolocationMarker.setMap(null);
}, [geolocationMarker, map]);
// update position, heading, size and accuracy
useEffect(() => {
if(!geolocationMarker) return;
geolocationMarker.position = position;
geolocationMarker.size = size;
geolocationMarker.heading = heading;
geolocationMarker.accuracy = accuracy;
}, [geolocationMarker, position, size, heading, accuracy]);
return <></>;
}; As for the geolocation-service, that really depends how your app is organized. You'll want to have that service running outside your app, writing into the state-management you are using. One important thing is that you need to do the permissions-query while handling a trusted event (for example, while handling a click event). I've also writtin on our blog about this: https://ubilabs.com/en/insights/implement-geolocation-and-compass-heading |
Beta Was this translation helpful? Give feedback.
-
thank you I managed to get what I needed like this
might not be the best but it does the job |
Beta Was this translation helpful? Give feedback.
thank you
I managed to get what I needed like this