|
|
@@ -1,7 +1,12 @@
|
|
1
|
|
-import { Component, OnInit, Input } from '@angular/core';
|
|
|
1
|
+import { Component, OnInit, Input, ViewChild, ElementRef } from '@angular/core';
|
|
2
|
2
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
3
|
3
|
import { WpServiceService } from '../wp-service.service';
|
|
4
|
4
|
|
|
|
5
|
+import { Geolocation } from '@ionic-native/geolocation/ngx';
|
|
|
6
|
+import { NativeGeocoder, NativeGeocoderResult, NativeGeocoderOptions } from '@ionic-native/native-geocoder/ngx';
|
|
|
7
|
+
|
|
|
8
|
+declare var google;
|
|
|
9
|
+
|
|
5
|
10
|
@Component({
|
|
6
|
11
|
selector: 'app-placedetail',
|
|
7
|
12
|
templateUrl: './placedetail.page.html',
|
|
|
@@ -12,7 +17,16 @@ export class PlacedetailPage implements OnInit {
|
|
12
|
17
|
data: any;
|
|
13
|
18
|
placelist: any;
|
|
14
|
19
|
|
|
15
|
|
- constructor(private wpservice: WpServiceService, private route: ActivatedRoute, private router: Router) { }
|
|
|
20
|
+ @ViewChild('map', { static: false }) mapElement: ElementRef;
|
|
|
21
|
+ map: any;
|
|
|
22
|
+ address: string;
|
|
|
23
|
+ latitude: number;
|
|
|
24
|
+ longitude: number;
|
|
|
25
|
+ latdynamic: any;
|
|
|
26
|
+ londynamic: any;
|
|
|
27
|
+
|
|
|
28
|
+
|
|
|
29
|
+ constructor(private wpservice: WpServiceService, private route: ActivatedRoute, private router: Router, private geolocation: Geolocation, private nativeGeocoder: NativeGeocoder) { }
|
|
16
|
30
|
@Input() id: string;
|
|
17
|
31
|
showDiss = false;
|
|
18
|
32
|
|
|
|
@@ -21,23 +35,107 @@ export class PlacedetailPage implements OnInit {
|
|
21
|
35
|
if (this.id != undefined) {
|
|
22
|
36
|
this.showDiss = true;
|
|
23
|
37
|
}
|
|
|
38
|
+ this.loadMap();
|
|
24
|
39
|
// console.log("showDiss ", this.showDiss);
|
|
25
|
40
|
// let id = this.route.snapshot.paramMap.get('id') || this.id;
|
|
26
|
41
|
// console.log("fetching ...");
|
|
27
|
42
|
// this.wpservice.getPlaceDetail(id).subscribe(data => {
|
|
28
|
|
- // let post = JSON.parse(data.data);
|
|
29
|
|
- // console.log(" get data ", post);
|
|
30
|
|
- // post['media_url'] = post['_embedded']['wp:featuredmedia'][0]['media_details'].sizes['medium'].source_url;
|
|
31
|
|
- // this.data = post;
|
|
|
43
|
+ // let post = JSON.parse(data.data);
|
|
|
44
|
+ // console.log(" get data ", post);
|
|
|
45
|
+ // post['media_url'] = post['_embedded']['wp:featuredmedia'][0]['media_details'].sizes['medium'].source_url;
|
|
|
46
|
+ // this.data = post;
|
|
32
|
47
|
let id = this.route.snapshot.paramMap.get('id') || this.id;
|
|
33
|
48
|
console.log("fetching ...");
|
|
34
|
49
|
this.wpservice.getPlaceDetail(id).subscribe((data) => {
|
|
35
|
|
- this.placelist = data;
|
|
|
50
|
+ this.placelist = data;
|
|
|
51
|
+ this.latdynamic = data['acf']['gmap']['lat'];
|
|
|
52
|
+ this.londynamic = data['acf']['gmap']['lng'];
|
|
36
|
53
|
console.log("load Place Detail ...");
|
|
|
54
|
+ console.log(this.latdynamic);
|
|
|
55
|
+ console.log("load Lati ...");
|
|
|
56
|
+ console.log(this.londynamic);
|
|
|
57
|
+ console.log("load Lon ...");
|
|
37
|
58
|
console.log(data);
|
|
38
|
59
|
}, error => {
|
|
39
|
60
|
console.log("errror ", error);
|
|
40
|
61
|
});
|
|
41
|
62
|
}
|
|
42
|
63
|
|
|
|
64
|
+ loadMap() {
|
|
|
65
|
+ this.geolocation.getCurrentPosition().then((resp) => {
|
|
|
66
|
+
|
|
|
67
|
+ this.latitude = resp.coords.latitude;
|
|
|
68
|
+ this.longitude = resp.coords.longitude;
|
|
|
69
|
+ // this.latdynamic = resp.coords.latitude;
|
|
|
70
|
+ // this.londynamic = resp.coords.longitude;
|
|
|
71
|
+
|
|
|
72
|
+ let latLng = new google.maps.LatLng(resp.coords.latitude, resp.coords.longitude);
|
|
|
73
|
+ let mapOptions = {
|
|
|
74
|
+ center: latLng,
|
|
|
75
|
+ zoom: 15,
|
|
|
76
|
+ mapTypeId: google.maps.MapTypeId.ROADMAP
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ this.getAddressFromCoords(resp.coords.latitude, resp.coords.longitude);
|
|
|
80
|
+
|
|
|
81
|
+ this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
|
|
|
82
|
+
|
|
|
83
|
+ this.map.addListener('dragend', () => {
|
|
|
84
|
+
|
|
|
85
|
+ this.latitude = this.map.center.lat();
|
|
|
86
|
+ this.longitude = this.map.center.lng();
|
|
|
87
|
+
|
|
|
88
|
+ this.getAddressFromCoords(this.map.center.lat(), this.map.center.lng())
|
|
|
89
|
+ });
|
|
|
90
|
+
|
|
|
91
|
+ }).catch((error) => {
|
|
|
92
|
+ console.log('Error getting location', error);
|
|
|
93
|
+ });
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ getAddressFromCoords(lattitude, longitude) {
|
|
|
97
|
+ console.log("getAddressFromCoords " + lattitude + " " + longitude);
|
|
|
98
|
+ let options: NativeGeocoderOptions = {
|
|
|
99
|
+ useLocale: true,
|
|
|
100
|
+ maxResults: 5
|
|
|
101
|
+ };
|
|
|
102
|
+
|
|
|
103
|
+ this.nativeGeocoder.reverseGeocode(lattitude, longitude, options)
|
|
|
104
|
+ .then((result: NativeGeocoderResult[]) => {
|
|
|
105
|
+ this.address = "";
|
|
|
106
|
+ let responseAddress = [];
|
|
|
107
|
+ for (let [key, value] of Object.entries(result[0])) {
|
|
|
108
|
+ if (value.length > 0)
|
|
|
109
|
+ responseAddress.push(value);
|
|
|
110
|
+
|
|
|
111
|
+ }
|
|
|
112
|
+ responseAddress.reverse();
|
|
|
113
|
+ for (let value of responseAddress) {
|
|
|
114
|
+ this.address += value + ", ";
|
|
|
115
|
+ }
|
|
|
116
|
+ this.address = this.address.slice(0, -2);
|
|
|
117
|
+ })
|
|
|
118
|
+ .catch((error: any) => {
|
|
|
119
|
+ this.address = "Address Not Available!";
|
|
|
120
|
+ });
|
|
|
121
|
+
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ // getAddressFromCoords2(lattitude, longitude) {
|
|
|
125
|
+ // console.log("getAddressFromCoords2 " + lattitude + " " + longitude);
|
|
|
126
|
+ // let options: NativeGeocoderOptions = {
|
|
|
127
|
+ // useLocale: true,
|
|
|
128
|
+ // maxResults: 5
|
|
|
129
|
+ // };
|
|
|
130
|
+ // }
|
|
|
131
|
+
|
|
|
132
|
+ // getGeoencoder(latitude, longitude) {
|
|
|
133
|
+ // this.nativeGeocoder.reverseGeocode(latitude, longitude, this.geoencoderOptions)
|
|
|
134
|
+ // .then((result: NativeGeocoderResult[]) => {
|
|
|
135
|
+ // this.address = this.generateAddress(result[0]);
|
|
|
136
|
+ // })
|
|
|
137
|
+ // .catch((error: any) => {
|
|
|
138
|
+ // alert('Error getting location' + JSON.stringify(error));
|
|
|
139
|
+ // });
|
|
|
140
|
+ // }
|
|
43
|
141
|
}
|