-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.component.ts
53 lines (48 loc) · 1.56 KB
/
map.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { MessageService } from "./../../services/message.service";
import { Component, OnInit, ViewChild } from "@angular/core";
import {} from "googlemaps";
import { MapsAPILoader } from "@agm/core";
@Component({
selector: "app-map",
templateUrl: "./map.component.html",
styleUrls: ["./map.component.css"],
})
export class MapComponent implements OnInit {
public lat;
public showDirection = false;
public lng;
@ViewChild("map") map: HTMLDivElement;
public origin: any;
public destination: any;
public distance: any;
public addresses: any[] = [];
constructor(
private mapsAPILoader: MapsAPILoader,
private msgService: MessageService
) {}
ngOnInit() {}
ngAfterViewInit() {
this.msgService.watchStorage().subscribe(() => {
const maps = JSON.parse(localStorage.getItem("maps"));
this.findAdress(maps.origin, maps.destination);
});
}
findAdress(a1, a2) {
this.mapsAPILoader.load().then(() => {
const service = new google.maps.places.AutocompleteService();
service.getPlacePredictions({ input: a1 }, this.displaySuggestions);
service.getPlacePredictions({ input: a2 }, this.displaySuggestions);
const div = document.getElementsByClassName("map-container");
});
}
displaySuggestions = (predictions, status) => {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
this.addresses.push(predictions[0].description);
this.origin = this.addresses[0];
this.destination = this.addresses[1];
console.log(this.origin, this.destination);
};
}