being forcast functoins
This commit is contained in:
1 parent
d9bcb0b0ec
commit
aafa52a497
1 file changed
+19
-19
@@ -4,12 +4,7 @@ const API_URL = "https://api.opencagedata.com/geocode/v1/json"
|
|||||||
let weather = {
|
let weather = {
|
||||||
apiKey: API_KEY,
|
apiKey: API_KEY,
|
||||||
fetchWeather: function (city) {
|
fetchWeather: function (city) {
|
||||||
fetch(
|
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${this.appkey}`)
|
||||||
"https://api.openweathermap.org/data/2.5/weather?q=" +
|
|
||||||
city +
|
|
||||||
"&units=metric&appid=" +
|
|
||||||
this.apiKey
|
|
||||||
)
|
|
||||||
.then((response) => { // error part if it fails
|
.then((response) => { // error part if it fails
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
alert("No weather found.");
|
alert("No weather found.");
|
||||||
@@ -38,21 +33,26 @@ let weather = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let forcast = {
|
||||||
|
apiKey: API_KEY,
|
||||||
|
fetchForcast: function(latitude, longitude) {
|
||||||
|
fetch(`https://api.openweathermap.org/data/2.5/forcast?lat=${latitude}&lon${longitude}&apiid=${this.apiKey}`)
|
||||||
|
.then((responce) => {
|
||||||
|
if (!responce.ok) {
|
||||||
|
alert("No forcast found");
|
||||||
|
throw new Error("No forcast found.");
|
||||||
|
}
|
||||||
|
return responce.json();
|
||||||
|
}).then((data) => this.displayForcast(data));
|
||||||
|
},
|
||||||
|
displayForcast: function(data) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let geocode = {
|
let geocode = {
|
||||||
reverseGeocode: function (latitude, longitude) {
|
reverseGeocode: function (latitude, longitude) {
|
||||||
var apikey = "5333f43e8a7a4553abee4745425cae8b";
|
var request_url = `${API_URL}?key=${API_KEY}&q=${encodeURIComponent(latitude+","+longitude)}&pretty=1&no_annotations=1`
|
||||||
|
|
||||||
var api_url = "https://api.opencagedata.com/geocode/v1/json";
|
|
||||||
|
|
||||||
var request_url =
|
|
||||||
api_url +
|
|
||||||
"?" +
|
|
||||||
"key=" +
|
|
||||||
apikey +
|
|
||||||
"&q=" +
|
|
||||||
encodeURIComponent(latitude + "," + longitude) +
|
|
||||||
"&pretty=1" +
|
|
||||||
"&no_annotations=1";
|
|
||||||
|
|
||||||
// see full list of required and optional parameters:
|
// see full list of required and optional parameters:
|
||||||
// https://opencagedata.com/api#forward
|
// https://opencagedata.com/api#forward
|
||||||
|
|||||||
Reference in new issue
Block a user