DirectionsService

The DirectionsService component wraps google.maps.DirectionsService and calls route whenever options changes.

Storybook

Open the DirectionsService story

Props

PropTypeDescription
optionsgoogle.maps.DirectionsRequestRoute request.
callback(result, status) => voidReceives the route result and status.
onLoad(service: google.maps.DirectionsService) => voidCalled after service creation.
onUnmount(service: google.maps.DirectionsService) => voidCalled before teardown.

Usage

<DirectionsService
  options={{ origin, destination, travelMode: 'DRIVING' }}
  callback={(result, status) => {
    directions = result ?? undefined;
    console.log(status);
  }}
/>
svelte