@@ -21,28 +21,26 @@ Using the `MapDirectionsService` requires the Directions API to be enabled in Go
2121
2222``` typescript
2323// google-maps-demo.component.ts
24- import {Component } from ' @angular/core' ;
24+ import {Component , inject } from ' @angular/core' ;
2525import {GoogleMap , MapDirectionsRenderer , MapDirectionsService } from ' @angular/google-maps' ;
26+ import {map } from ' rxjs/operators' ;
2627
2728@Component ({
2829 selector: ' google-map-demo' ,
2930 templateUrl: ' google-map-demo.html' ,
30- imports: [GoogleMap , MapDirectionsRenderer ],
31+ imports: [GoogleMap , MapDirectionsRenderer ],
3132})
3233export class GoogleMapDemo {
3334 center: google .maps .LatLngLiteral = {lat: 24 , lng: 12 };
3435 zoom = 4 ;
3536
36- readonly directionsResults$ : Observable < google . maps . DirectionsResult | undefined > ;
37+ private mapDirectionsService = inject ( MapDirectionsService ) ;
3738
38- constructor (mapDirectionsService : MapDirectionsService ) {
39- const request: google .maps .DirectionsRequest = {
40- destination: {lat: 12 , lng: 4 },
41- origin: {lat: 14 , lng: 8 },
42- travelMode: google .maps .TravelMode .DRIVING
43- };
44- this .directionsResults$ = mapDirectionsService .route (request ).pipe (map (response => response .result ));
45- }
39+ readonly directionsResults$ = this .mapDirectionsService .route ({
40+ destination: {lat: 12 , lng: 4 },
41+ origin: {lat: 14 , lng: 8 },
42+ travelMode: google .maps .TravelMode .DRIVING ,
43+ }).pipe (map (response => response .result ));
4644}
4745```
4846
0 commit comments