Skip to content

Commit decca6b

Browse files
google maps api code complete and working
1 parent a9eab8f commit decca6b

15 files changed

+229
-37
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Code taken from course.
1919
* App to view and book places to stay. All places listed on the 'discover.page' and clicking on an item navigates to a place detail page using the place id in the browser.
2020
* Places are displayed under 2 list option: 'ALL PLACES' and 'BOOKABLE PLACES'. The first place is displayed using an ion-card, the remaining places are displayed using a list with a thumbnail image. There is code to prevent the user from being able to book their own places, using a userId matching function.
2121
* Places can be booked, listed and cancelled.
22-
* New places can be added.
22+
* New places can be added. The location of the new place is chosen using google maps and is stored in the Places array to be displayed in the template using data-binding.
2323
* Burger side panel added with links to the discover places listings, your bookings and a logout button.
24-
* Bottom menu with 2 links to 'Discover' (default page upon loading) and 'Offers' that lists all the places available. At the moment these lists are the same.
24+
* Bottom menu with 2 links to 'Discover' (default page upon loading) and 'Offers' that lists all the places available.
2525

2626
## Screenshots
2727

@@ -35,6 +35,7 @@ Code taken from course.
3535
* [Ionic/angular v 4.7.1](https://ionicframework.com/)
3636
* [RxJS](https://angular.io/guide/rx-library)
3737
* [Google Firebase](https://firebase.google.com)
38+
* [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/tutorial)
3839

3940
## Setup
4041

@@ -86,7 +87,7 @@ private getGoogleMaps(): Promise<any> {
8687
* [Firebase backend database](https://firebase.google.com) used to store place and booking data.
8788
* Bookings can be cancelled from booking.page.
8889
* Place details can be edited (as long as user id matches) using a neat button that slides from the right.
89-
* [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/tutorial) map-modal added to new-offer page. Clicking on 'SELECT LOCATION' will open Google Maps at a fixed location.
90+
* [Google Maps Javascript API](https://developers.google.com/maps/documentation/javascript/tutorial) map-modal added to new-offer page. Clicking on 'SELECT LOCATION' will open Google Maps at a fixed location. Address of place extracted from Google Maps data and stored in Places database.
9091

9192
## Status & To-do list
9293

src/app/places/discover/place-detail/place-detail.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import { NgModule } from '@angular/core';
23
import { CommonModule } from '@angular/common';
34
import { FormsModule } from '@angular/forms';
@@ -7,6 +8,7 @@ import { IonicModule } from '@ionic/angular';
78

89
import { PlaceDetailPage } from './place-detail.page';
910
import { CreateBookingComponent } from './../../../bookings/create-booking/create-booking.component';
11+
import { SharedModule } from '../../../shared/shared.module';
1012

1113
const routes: Routes = [
1214
{
@@ -20,7 +22,8 @@ const routes: Routes = [
2022
CommonModule,
2123
FormsModule,
2224
IonicModule,
23-
RouterModule.forChild(routes)
25+
RouterModule.forChild(routes),
26+
SharedModule
2427
],
2528
declarations: [PlaceDetailPage, CreateBookingComponent],
2629
entryComponents: [CreateBookingComponent]

src/app/places/discover/place-detail/place-detail.page.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
</ion-col>
2626
</ion-row>
2727

28+
<ion-row>
29+
<ion-col size-sm="6" offset-sm="3" padding text-center>
30+
<p>{{ place.location.address }}</p>
31+
</ion-col>
32+
</ion-row>
33+
34+
<ion-row>
35+
<ion-col size-sm="6" offset-sm="3" no-padding>
36+
<ion-img role="button" (click)="onShowFullMap()" class="location-image" [src]="place.location.staticMapImageUrl"></ion-img>
37+
</ion-col>
38+
</ion-row>
39+
2840
<ion-row *ngIf="isBookable">
2941
<ion-col size-sm="6" offset-sm="3" text-center>
3042
<ion-button color="primary" margin (click)="onBookPlace()">Book</ion-button>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.location-image {
2+
width: 100%;
3+
height: 100%;
4+
max-height: 30vh;
5+
object-fit: cover;
6+
}
7+
8+
p {
9+
margin: 0;
10+
}

src/app/places/discover/place-detail/place-detail.page.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { Subscription } from 'rxjs';
55

66
import { PlacesService } from '../../places.service';
77
import { Place } from '../../place.model';
8-
import { CreateBookingComponent } from './../../../bookings/create-booking/create-booking.component';
8+
import { CreateBookingComponent } from '../../../bookings/create-booking/create-booking.component';
99
import { AuthService } from '../../../auth/auth.service';
1010
import { BookingService } from '../../../bookings/booking.service';
11-
import { Booking } from './../../../bookings/booking.model';
11+
import { MapModalComponent } from '../../../shared/map-modal/map-modal.component';
1212

1313
@Component({
1414
selector: 'app-place-detail',
@@ -128,6 +128,25 @@ export class PlaceDetailPage implements OnInit, OnDestroy {
128128
});
129129
}
130130

131+
onShowFullMap() {
132+
this.modalCtrl
133+
.create({
134+
component: MapModalComponent,
135+
componentProps: {
136+
center: {
137+
lat: this.place.location.lat,
138+
lng: this.place.location.lng
139+
},
140+
selectable: false,
141+
closeButtonText: 'Close',
142+
title: this.place.location.address
143+
}
144+
})
145+
.then(modalEl => {
146+
modalEl.present();
147+
});
148+
}
149+
131150
ngOnDestroy() {
132151
if (this.placeSub) {
133152
this.placeSub.unsubscribe();

src/app/places/location.model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface Coordinates {
2+
lat: number;
3+
lng: number;
4+
}
5+
6+
export interface PlaceLocation extends Coordinates {
7+
address: string;
8+
staticMapImageUrl: string;
9+
}

src/app/places/offers/new-offer/new-offer.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
<ion-row>
7777
<ion-col size-sm="3" offset-sm="3">
78-
<app-location-picker></app-location-picker>
78+
<app-location-picker (locationPick)="onLocationPicked($event)"></app-location-picker>
7979
</ion-col>
8080
</ion-row>
8181

src/app/places/offers/new-offer/new-offer.page.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
12
import { LoadingController } from '@ionic/angular';
23
import { Router } from '@angular/router';
34
import { Component, OnInit } from '@angular/core';
45
import { FormGroup, FormControl, Validators } from '@angular/forms';
56

7+
import { PlaceLocation } from './../../location.model';
68
import { PlacesService } from '../../places.service';
79

810
@Component({
@@ -36,10 +38,15 @@ export class NewOfferPage implements OnInit {
3638
dateTo: new FormControl(null, {
3739
updateOn: 'blur',
3840
validators: [Validators.required]
39-
})
41+
}),
42+
location: new FormControl(null, { validators: [Validators.required]})
4043
});
4144
}
4245

46+
onLocationPicked(location: PlaceLocation) {
47+
this.form.patchValue({location});
48+
}
49+
4350
onCreateOffer() {
4451
if (!this.form.valid) {
4552
return;
@@ -56,7 +63,8 @@ export class NewOfferPage implements OnInit {
5663
this.form.value.description,
5764
+this.form.value.price,
5865
new Date(this.form.value.dateFrom),
59-
new Date(this.form.value.dateTo)
66+
new Date(this.form.value.dateTo),
67+
this.form.value.location
6068
)
6169
.subscribe(() => {
6270
loadingEl.dismiss();

src/app/places/place.model.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PlaceLocation } from './location.model';
2+
13
export class Place {
24
constructor(
35
public id: string,
@@ -7,6 +9,7 @@ export class Place {
79
public price: number,
810
public availableFrom: Date,
911
public availableTo: Date,
10-
public userId: string
12+
public userId: string,
13+
public location: PlaceLocation
1114
) {}
1215
}

src/app/places/places.service.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Injectable } from '@angular/core';
22
import { Place } from './place.model';
33
import { BehaviorSubject, of } from 'rxjs';
44
import { take, map, tap, switchMap } from 'rxjs/operators';
5+
import { HttpClient } from '@angular/common/http';
56

67
import { AuthService } from '../auth/auth.service';
7-
import { HttpClient } from '@angular/common/http';
8+
import { PlaceLocation } from './location.model';
89

910
interface PlaceData {
1011
availableFrom: string;
@@ -14,6 +15,7 @@ interface PlaceData {
1415
price: number;
1516
title: string;
1617
userId: string;
18+
location: PlaceLocation;
1719
}
1820

1921
// new Place(
@@ -81,7 +83,8 @@ export class PlacesService {
8183
resData[key].price,
8284
new Date(resData[key].availableFrom),
8385
new Date(resData[key].availableTo),
84-
resData[key].userId
86+
resData[key].userId,
87+
resData[key].location
8588
)
8689
);
8790
}
@@ -109,7 +112,8 @@ export class PlacesService {
109112
placeData.price,
110113
new Date(placeData.availableFrom),
111114
new Date(placeData.availableTo),
112-
placeData.userId
115+
placeData.userId,
116+
placeData.location
113117
);
114118
})
115119
);
@@ -120,7 +124,8 @@ export class PlacesService {
120124
description: string,
121125
price: number,
122126
dateFrom: Date,
123-
dateTo: Date
127+
dateTo: Date,
128+
location: PlaceLocation
124129
) {
125130
let generatedId: string;
126131
const newPlace = new Place
@@ -132,7 +137,8 @@ export class PlacesService {
132137
price,
133138
dateFrom,
134139
dateTo,
135-
this.authService.userId
140+
this.authService.userId,
141+
location
136142
);
137143

138144
// post newPlace data to Firebase but replace id with null
@@ -191,7 +197,8 @@ export class PlacesService {
191197
oldPlace.price,
192198
oldPlace.availableFrom,
193199
oldPlace.availableTo,
194-
oldPlace.userId
200+
oldPlace.userId,
201+
oldPlace.location
195202
);
196203
return this.http.put(
197204
`https://ionic-angular-project-a9d42.firebaseio.com/offered-places/${placeId}.json`,

0 commit comments

Comments
 (0)