File tree 2 files changed +59
-3
lines changed
2 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -486,7 +486,7 @@ React hook to use the [Google Maps Distance Matrix Service](https://developers.g
486
486
487
487
#### Usage
488
488
489
- ``` jsx
489
+ ``` tsx
490
490
import React from ' react' ;
491
491
import { useDistanceMatrix } from ' @ubilabs/google-maps-react-hooks' ;
492
492
@@ -501,14 +501,45 @@ const MyComponent = () => {
501
501
};
502
502
` ` `
503
503
504
- #### Return value
505
-
506
504
Returns the [ ` DistanceMatrixService ` ](google.maps.DistanceMatrixService) class to use directly.
507
505
508
506
` ` ` TypeScript
509
507
google .maps .DistanceMatrixService
510
508
` ` `
511
509
510
+ ### useElevationService
511
+
512
+ React hook to use the [Elevation Service](https://developers.google.com/maps/documentation/javascript/elevation) in any component.
513
+
514
+ #### Usage
515
+
516
+ ` ` ` tsx
517
+ import React , {useEffect } from ' react' ;
518
+ import {useElevationService } from ' @ubilabs/google-maps-react-hooks' ;
519
+
520
+ const MyComponent = () => {
521
+ const elevator = useElevationService ();
522
+ const location = /** google.maps.LatLng */ ;
523
+
524
+ useEffect (() => {
525
+ elevator ?.getElevationForLocations (
526
+ {locations: [location ]},
527
+ (results : google .maps .ElevationResult []) => {
528
+ // Do something with results
529
+ }
530
+ );
531
+ }, [location ]);
532
+ ` ` `
533
+
534
+ #### Return value
535
+
536
+ Returns the [ ` ElevationService ` ](google.maps.places.ElevationService) class to use directly.
537
+
538
+ ` ` ` TypeScript
539
+ google .maps .places .ElevationService
540
+ ` ` `
541
+
542
+
512
543
## Publish (only for maintainers)
513
544
514
545
` npm publish -- access public `
Original file line number Diff line number Diff line change
1
+ import { useMemo } from 'react' ;
2
+
3
+ import useGoogleMap from './map-instance' ;
4
+
5
+ /**
6
+ * Hook to get Elevation Service instance
7
+ */
8
+ const useElevationService = ( ) : google . maps . ElevationService | null => {
9
+ const { map} = useGoogleMap ( ) ;
10
+
11
+ // Creates an 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 useElevationService ;
You can’t perform that action at this time.
0 commit comments