-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (76 loc) · 2.16 KB
/
Copy pathscript.js
File metadata and controls
89 lines (76 loc) · 2.16 KB
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
// 'use strict';
// // geolocation
// function success(pos){
// ajaxRequest(
// pos.coords.latitude,
// pos.coords.longitude
// );
// }
// function fail(error){
// alert('位置情報の取得に失敗しました。エラーコード:' + error.code);
// }
// navigator.geolocation.getCurrentPosition(success, fail);
// //データ取得
// function ajaxRequest(lat, long){
// const URL = 'https://pro.openweathermap.org/data/2.5/forecast/hourly';
// const APP_ID = 'pro.openweathermap.org/data/2.5/forecast/hourly';
// $.ajax({
// url: URL,
// data: {
// appid: APP_ID,
// lat: lat,
// lon: long,
// units: 'metric',
// lang: 'ja'
// }
// })
// .done(function(data){
// console.log(data);
// })
// .fail(function(){
// console.log('$.ajax failed!');
// })
// }
// // var settings = {
// // "async": true,
// // "crossDomain": true,
// // "url": "https://mxrck-ser-programadores-apis.p.rapidapi.com/weather/forecast/MXCE0008/c.json?lang=es",
// // "method": "GET",
// // "headers": {
// // "x-rapidapi-host": "mxrck-ser-programadores-apis.p.rapidapi.com",
// // "x-rapidapi-key": "3840757b10mshcdb44212cd66ca2p1a927ejsnb8482768e8df"
// // }
// // }
// // $.ajax(settings).done(function (response) {
// // console.log(response);
// // });
'use strict';
// geolocation
function success(pos) {
ajaxRequest(pos.coords.latitude, pos.coords.longitude);
}
function fail(error) {
alert('位置情報の取得に失敗しました。エラーコード:' + error.code);
}
navigator.geolocation.getCurrentPosition(success, fail);
// データ取得
function ajaxRequest(lat, long) {
const url = 'https://api.openweathermap.org/data/2.5/forecast';
const appId = 'addef0382c5e95dc97cdae7a9878699d';
$.ajax({
url: url,
data: {
appid: appId,
lat: lat,
lon: long,
units: 'metric',
lang: 'ja'
}
})
.done(function(data) {
console.log(data);
})
.fail(function() {
console.log('$.ajax failed!');
})
}