UNPKG

@syncromatics/react-google-maps

Version:
51 lines (46 loc) 1.38 kB
### Map with a DirectionsRenderer ```jsx const { compose, withProps, lifecycle } = require("recompose"); const { withScriptjs, withGoogleMap, GoogleMap, DirectionsRenderer, } = require("@syncromatics/react-google-maps"); const MapWithADirectionsRenderer = compose( withProps({ googleMapURL: GOOGLE_MAP_URL, loadingElement: <div style={{ height: `100%` }} />, containerElement: <div style={{ height: `400px` }} />, mapElement: <div style={{ height: `100%` }} />, }), withScriptjs, withGoogleMap, lifecycle({ componentDidMount() { const DirectionsService = new google.maps.DirectionsService(); DirectionsService.route({ origin: new google.maps.LatLng(41.8507300, -87.6512600), destination: new google.maps.LatLng(41.8525800, -87.6514100), travelMode: google.maps.TravelMode.DRIVING, }, (result, status) => { if (status === google.maps.DirectionsStatus.OK) { this.setState({ directions: result, }); } else { console.error(`error fetching directions ${result}`); } }); } }) )(props => <GoogleMap defaultZoom={7} defaultCenter={new google.maps.LatLng(41.8507300, -87.6512600)} > {props.directions && <DirectionsRenderer directions={props.directions} />} </GoogleMap> ); <MapWithADirectionsRenderer /> ```