Skip to content

Commit 2c2fe2c

Browse files
committed
feat(hooks): add elevation hook
1 parent be9d081 commit 2c2fe2c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/hooks/elevation.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {useMemo} from 'react';
2+
3+
import useGoogleMap from './map-instance';
4+
5+
/**
6+
* Hook to get Elevation Service instance
7+
*/
8+
const useElevation = (): google.maps.ElevationService | null => {
9+
const {map} = useGoogleMap();
10+
11+
// Creates a Elevation Service instance
12+
const elevationService =
13+
useMemo<google.maps.ElevationService | null>(() => {
14+
// Wait for map to be initialized
15+
if (!map) {
16+
return null;
17+
}
18+
19+
return new google.maps.ElevationService();
20+
}, [map]);
21+
22+
return elevationService;
23+
};
24+
25+
export default useElevation;

0 commit comments

Comments
 (0)