@@ -3,6 +3,7 @@ import { FormControl, ReactiveFormsModule } from '@angular/forms';
33import { GMapsDirectionsService } from 'app/common/states/gmaps.service' ;
44import { } from '@types/googlemaps' ;
55import { GoogleMapsAPIWrapper , MapsAPILoader } from '@agm/core' ;
6+ import { error } from 'util' ;
67
78@Component ( {
89 selector : 'app-trip-planner' ,
@@ -22,6 +23,8 @@ export class TripPlannerComponent implements OnInit {
2223 @Input ( ) private destination : any ;
2324 @Input ( ) private estimatedTime : any ;
2425 @Input ( ) private estimatedDistance : any ;
26+ @Input ( ) private initialLat : number ;
27+ @Input ( ) private initialLng : number ;
2528
2629 @ViewChild ( "pickupInput" )
2730 public pickupInputElementRef : ElementRef ;
@@ -39,10 +42,18 @@ export class TripPlannerComponent implements OnInit {
3942 }
4043
4144 ngOnInit ( ) {
42- //Default Map View
43- this . latitude = 26.089595 ;
44- this . longitude = - 80.366791 ;
45- this . zoom = 14 ;
45+ //Set Default Map View
46+ this . setInitialLatitude ( ) . then (
47+ ( ) => this . setInitialLongitude ( ) . then (
48+ ( ) => {
49+ this . latitude = this . initialLat ;
50+ this . longitude = this . initialLng ;
51+ this . zoom = 14 ;
52+ console . log ( "set lat and lng" )
53+ } ,
54+ ) ) . catch ( ( error ) => {
55+ console . log ( "error occurred" ) ;
56+ } ) ;
4657
4758 this . destinationInput = new FormControl ( ) ;
4859 this . destinationOutput = new FormControl ( ) ;
@@ -103,8 +114,37 @@ export class TripPlannerComponent implements OnInit {
103114 this . estimatedDistance = this . service . estimatedDistance ;
104115 }
105116
106- onFindRideClick ( event ) {
107- console . log ( "Clicked find ride." ) ;
117+ setInitialLatitude ( ) {
118+ var promise = new Promise ( ( resolve , reject ) => {
119+ if ( "geolocation" in navigator ) {
120+ navigator . geolocation . getCurrentPosition ( ( position ) => {
121+ this . initialLat = position . coords . latitude ;
122+ //resolve();
123+ } ) ;
124+ }
125+ if ( error ) {
126+ reject ( ) ;
127+ } else {
128+ resolve ( ) ;
129+ }
130+ } ) ;
131+ return promise ;
132+ }
133+
134+ setInitialLongitude ( ) {
135+ var promise = new Promise ( ( resolve , reject ) => {
136+ if ( "geolocation" in navigator ) {
137+ navigator . geolocation . getCurrentPosition ( ( position ) => {
138+ this . initialLng = position . coords . longitude ;
139+ } ) ;
140+ }
141+ if ( error ) {
142+ reject ( ) ;
143+ } else {
144+ resolve ( ) ;
145+ }
146+ } ) ;
147+ return promise ;
108148 }
109149
110150}
0 commit comments