-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.js
124 lines (88 loc) · 3.24 KB
/
address.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// find user current location
window.onload = function () {
findUserLocation();
};
// current location
function findUserLocation() {
const options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0,
};
function error(errorMsg) {
console.warn(`Location Error(${errorMsg.code}): ${errorMsg.message}`);
}
function findLocation(pos) {
const crd = pos.coords;
let latitude = crd.latitude;
let longitude = crd.longitude;
let accuracy = crd.accuracy;
let userCurrentPosition = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=0c8ad3128f981928e8934de5e0264b44`;
async function findPlace() {
let res = await fetch(userCurrentPosition);
if (res.status == 200) {
let jsonFormat = await res.json();
let location = jsonFormat.name;
changeMap(location);
}
}
findPlace();
}
navigator.geolocation.getCurrentPosition(findLocation, error, options);
}
let submitBtn = document.querySelector("#submit-btn");
submitBtn.onclick = function (){
let cityName = document.querySelector("#city-name").value;
let deliveryAddress = document.querySelector("#delivery-address").value;
let phonenumber = document.querySelector("#phonenumber").value;
let zipCode = document.querySelector("#zip-code").value;
let cityWarn = document.querySelector(".city-warn");
let addressWarn = document.querySelector(".address-warn");
let phonenumberWarn = document.querySelector(".phonenumber-warn");
let zipWarn = document.querySelector(".zip-warn");
if (!cityName){
cityWarn.classList.add("display-block");
}else {
cityWarn.classList.remove("display-block");
}
if (!deliveryAddress){
addressWarn.classList.add("display-block");
}else {
addressWarn.classList.remove("display-block")
}
if (!phonenumber){
phonenumberWarn.classList.add("display-block");
}else {
phonenumberWarn.classList.remove("display-block");
}
if (!zipCode){
zipWarn.classList.add("display-block");
}else {
zipWarn.classList.remove("display-block");
}
if (cityName && deliveryAddress && phonenumber && zipCode){
let userAddressData = new AddressConstructor (cityName, deliveryAddress, phonenumber, zipCode)
localStorage.setItem("addressData", JSON.stringify(userAddressData));
window.location.href = "payment.html"
}
}
document.getElementById("city-name").addEventListener("keydown", function (event){
if (event.key === "Enter"){
let city = document.querySelector("#city-name").value
changeMap(city);
}
})
function changeMap(location) {
let mapCanvas = document.querySelector("#gmap_canvas");
mapCanvas.src =
"https://maps.google.com/maps?q=" +
location +
"&t=&z=13&ie=UTF8&iwloc=&output=embed";
}
function AddressConstructor (cityName, deliveryAddress, phonenumber, zipCode){
this.cityName = cityName;
this.deliveryAddress = deliveryAddress;
this.phonenumber = phonenumber;
this.zipCode = zipCode;
}
let submit2 = document.querySelector("#submit-btn");