File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -501,6 +501,8 @@ const MyComponent = () => {
501501};
502502` ` `
503503
504+ #### Return value
505+
504506Returns the [ ` DistanceMatrixService ` ](google.maps.DistanceMatrixService) class to use directly.
505507
506508` ` ` TypeScript
@@ -529,14 +531,54 @@ const MyComponent = () => {
529531 }
530532 );
531533 }, [location ]);
534+
535+ return (... );
536+ };
532537` ` `
533538
539+ #### Return value
540+
534541Returns the [ ` MaxZoomService ` ](google.maps.places.MaxZoomService) class to use directly.
535542
536543` ` ` TypeScript
537544google .maps .places .MaxZoomService
538545` ` `
539546
547+ ### useElevationService
548+
549+ React hook to use the [Elevation Service](https://developers.google.com/maps/documentation/javascript/elevation) in any component.
550+
551+ #### Usage
552+
553+ ` ` ` tsx
554+ import React , {useEffect } from ' react' ;
555+ import {useElevationService } from ' @ubilabs/google-maps-react-hooks' ;
556+
557+ const MyComponent = () => {
558+ const elevator = useElevationService ();
559+ const location = /** google.maps.LatLng */ ;
560+
561+ useEffect (() => {
562+ elevator ?.getElevationForLocations (
563+ {locations: [location ]},
564+ (results : google .maps .ElevationResult []) => {
565+ // Do something with results
566+ }
567+ );
568+ }, [location ]);
569+
570+ return (... );
571+ };
572+ ` ` `
573+
574+ #### Return value
575+
576+ Returns the [ ` ElevationService ` ](google.maps.places.ElevationService) class to use directly.
577+
578+ ` ` ` TypeScript
579+ google .maps .places .ElevationService
580+ ` ` `
581+
540582## Publish (only for maintainers)
541583
542584` 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