Source: https://developers.woosmap.com/products/mobile/react-native/direction/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Woosmap for React Native - Driving Directions



You can calculate directions and plot by using the `WoosmapView.route` method. This method is an interface to the Route endpoint of Woosmap Distance API. This service compute travel distance, time and path for a pair of origin and destination.

You can use the `WoosmapView.setRoute` method to display these results.

``` typescript
import {
  WoosmapView,
  MapController,
  LatLngBounds,
  WoosPadding,
  LatLng,
  DirectionRequest
} from '@woosmap/react-native-woosmap';
// ...
<WoosmapView
        ref={mapRef}
        mapOptions={mapOptions}
        wooskey={'Your Woosmap key'}
        routeIndex_changed={(routeInfo) => {
          console.log(`route Index changed ${JSON.stringify(routeInfo)}`);
        }}}
      />

```

To display route on map.

``` typescript
    mapRef.current?.route(
        {
          origin: { lat: 48.86288, lng: 2.34946 },
          destination: { lat: 52.52457, lng: 13.42347 },
          provideRouteAlternatives: true,
          travelMode: 'driving',
          unitSystem: 'metric',
        }
      )
      .then((result) => {
          console.log(JSON.stringify(result));
          mapRef.current?.setRoute(result);
       });
```

 To clear displayed route on map.

``` typescript
mapRef.current?.setRoute(undefined);
```

Please check the javascript guide for more implementation. [javascript guide](/products/distance-api/reference/map-js-sdk/)

## Get Transit Route

You can calculate transit route by using the [TransitService](/products/mobile/react-native/services/#transit-api) object. This object is an interface to the Route endpoint of Woosmap Transit API. This service compute travel distance, time and path for a pair of origin and destination.

``` typescript
  if (mapRef.current) {
    let api = new WoosmapApi({ publicKey: appConstants.woosmap_key });
    api.Transit.route({
      origin: { lat: 45.467, lng: 9.0516 },
      destination: { lat: 45.4599, lng: 9.2822 },
      modes: [
        `highSpeedTrain`,
        `intercityTrain`,
        `interRegionalTrain`,
        `regionalTrain`,
        `cityTrain`,
        `bus`,
        `ferry`,
        `subway`,
        `lightRail`,
        `privateBus`,
        `inclined`,
        `aerial`,
        `busRapid`,
        `monorail`,
        `flight`,
        `spaceship`,
      ],
    })
      .then((result: TransitRouteResponse) => {
        //console.log(JSON.stringify(result));
        mapRef.current?.setTransitRoute(result);
      })
      .catch((err) => {
        Alert.alert('Transit Direction', `Error: ${err.message}`);
      });
  }
```

 To clear displayed route on map.

``` typescript
  if (mapRef.current) {
    mapRef.current?.setTransitRoute(undefined);
  }
```

Please check the javascript guide for more implementation. [javascript guide](/products/map-api/guides/transit/)
