traveling.app 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/main.js +159 -0
- package/package.json +17 -0
- package/tea.yaml +8 -0
package/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# travelingfinder
|
package/main.js
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
const axios = require('axios');
|
2
|
+
const readlineSync = require('readline-sync');
|
3
|
+
|
4
|
+
const apiUrl = 'https://api.opentripmap.com/0.1/en/places/radius';
|
5
|
+
const apiKey = '5ae2e3f221c38a28845f05b6d846ee30763e7022043ccdb84ffcdb22'; // Ganti dengan kunci API Anda dari OpenTripMap
|
6
|
+
const latitude = '51.5074'; // Koordinat London sebagai contoh
|
7
|
+
const longitude = '-0.1278';
|
8
|
+
const radius = '10000'; // Radius dalam meter
|
9
|
+
|
10
|
+
// Fungsi untuk menghitung jarak antara dua titik koordinat
|
11
|
+
const calculateDistance = (lat1, lon1, lat2, lon2) => {
|
12
|
+
const R = 6371e3; // Radius bumi dalam meter
|
13
|
+
const φ1 = lat1 * Math.PI / 180;
|
14
|
+
const φ2 = lat2 * Math.PI / 180;
|
15
|
+
const Δφ = (lat2 - lat1) * Math.PI / 180;
|
16
|
+
const Δλ = (lon2 - lon1) * Math.PI / 180;
|
17
|
+
|
18
|
+
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
|
19
|
+
Math.cos(φ1) * Math.cos(φ2) *
|
20
|
+
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
|
21
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
22
|
+
|
23
|
+
return R * c;
|
24
|
+
};
|
25
|
+
|
26
|
+
// Fungsi untuk melakukan filter tempat wisata berdasarkan kategori
|
27
|
+
const filterByCategory = (places, category) => {
|
28
|
+
return places.filter(place => place.category.includes(category));
|
29
|
+
};
|
30
|
+
|
31
|
+
// Panggil API untuk mendapatkan data tempat wisata
|
32
|
+
axios.get(`${apiUrl}?apikey=${apiKey}&radius=${radius}&lon=${longitude}&lat=${latitude}`)
|
33
|
+
.then(response => {
|
34
|
+
const places = response.data.features.map(place => ({
|
35
|
+
name: place.properties.name,
|
36
|
+
rating: place.properties.rate,
|
37
|
+
popularity: place.properties.popularity,
|
38
|
+
category: place.properties.kinds,
|
39
|
+
distance: calculateDistance(latitude, longitude, place.geometry.coordinates[1], place.geometry.coordinates[0])
|
40
|
+
// Properti lain yang diperlukan bisa ditambahkan di sini
|
41
|
+
}));
|
42
|
+
|
43
|
+
// Logika tambahan setelah mendapatkan data tempat wisata
|
44
|
+
console.log('Data Tempat Wisata:', places);
|
45
|
+
|
46
|
+
// Logika tambahan
|
47
|
+
const sortedByRating = places.sort((a, b) => b.rating - a.rating);
|
48
|
+
console.log('Tempat Wisata Berdasarkan Rating Tertinggi:', sortedByRating);
|
49
|
+
|
50
|
+
// Fungsi tambahan
|
51
|
+
const getNearestPlace = (places, userLatitude, userLongitude) => {
|
52
|
+
let nearestPlace;
|
53
|
+
let minDistance = Infinity;
|
54
|
+
|
55
|
+
places.forEach(place => {
|
56
|
+
if (place.geometry && place.geometry.coordinates) {
|
57
|
+
const distance = calculateDistance(userLatitude, userLongitude, place.geometry.coordinates[1], place.geometry.coordinates[0]);
|
58
|
+
if (distance < minDistance) {
|
59
|
+
minDistance = distance;
|
60
|
+
nearestPlace = place;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
});
|
64
|
+
|
65
|
+
return nearestPlace;
|
66
|
+
};
|
67
|
+
|
68
|
+
const displayPlaceDetails = (places, placeName) => {
|
69
|
+
const selectedPlace = places.find(place => place.name.toLowerCase() === placeName.toLowerCase());
|
70
|
+
if (selectedPlace) {
|
71
|
+
console.log('Detail Tempat Wisata:', selectedPlace);
|
72
|
+
} else {
|
73
|
+
console.log('Tempat wisata tidak ditemukan.');
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
const sortByDistance = (places, userLatitude, userLongitude) => {
|
78
|
+
return places.sort((a, b) => a.distance - b.distance);
|
79
|
+
};
|
80
|
+
|
81
|
+
const filterByRatingRange = (places, minRating, maxRating) => {
|
82
|
+
return places.filter(place => place.rating >= minRating && place.rating <= maxRating);
|
83
|
+
};
|
84
|
+
|
85
|
+
// Contoh penggunaan fungsi tambahan
|
86
|
+
const nearestPlace = getNearestPlace(places, latitude, longitude);
|
87
|
+
console.log('Tempat Wisata Terdekat:', nearestPlace);
|
88
|
+
|
89
|
+
displayPlaceDetails(places, 'London Eye');
|
90
|
+
|
91
|
+
const sortedByDistance = sortByDistance(places, latitude, longitude);
|
92
|
+
console.log('Tempat Wisata Berdasarkan Jarak:', sortedByDistance);
|
93
|
+
|
94
|
+
const ratedPlaces = filterByRatingRange(places, 4, 5); // Tempat dengan rating antara 4 dan 5
|
95
|
+
console.log('Tempat Wisata dengan Rating 4-5:', ratedPlaces);
|
96
|
+
|
97
|
+
// Mulai interaksi dengan pengguna untuk memilih kategori tempat wisata
|
98
|
+
const showCategoryOptions = () => {
|
99
|
+
console.log('Pilih kategori tempat wisata:');
|
100
|
+
console.log('1. Alam');
|
101
|
+
console.log('2. Sejarah');
|
102
|
+
console.log('3. Makanan');
|
103
|
+
};
|
104
|
+
|
105
|
+
// Fungsi untuk menampilkan hasil rekomendasi
|
106
|
+
const displayRecommendations = (places) => {
|
107
|
+
console.log('Hasil Rekomendasi:');
|
108
|
+
places.forEach(place => {
|
109
|
+
console.log(`- ${place.name} (${place.category}), Rating: ${place.rating}, Jarak: ${place.distance} meter`);
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
// Fungsi untuk memulai interaksi dengan pengguna
|
114
|
+
const askCategory = () => {
|
115
|
+
showCategoryOptions(); // Menampilkan pilihan kategori
|
116
|
+
const answer = readlineSync.question('Masukkan pilihan kategori (1/2/3): ');
|
117
|
+
|
118
|
+
let category;
|
119
|
+
switch (answer) {
|
120
|
+
case '1':
|
121
|
+
category = 'natural';
|
122
|
+
break;
|
123
|
+
case '2':
|
124
|
+
category = 'historic';
|
125
|
+
break;
|
126
|
+
case '3':
|
127
|
+
category = 'restaurant';
|
128
|
+
break;
|
129
|
+
case 'exit':
|
130
|
+
console.log('Terima kasih telah menggunakan aplikasi.');
|
131
|
+
return;
|
132
|
+
default:
|
133
|
+
console.log('Pilihan kategori tidak valid.');
|
134
|
+
askCategory(); // Mengulang pertanyaan jika input tidak valid
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
|
138
|
+
// Filter tempat wisata berdasarkan kategori yang dipilih
|
139
|
+
const filteredPlaces = filterByCategory(places, category);
|
140
|
+
|
141
|
+
// Tampilkan hasil rekomendasi
|
142
|
+
displayRecommendations(filteredPlaces);
|
143
|
+
|
144
|
+
// Menanyakan apakah pengguna ingin melihat detail atau keluar
|
145
|
+
const detailAnswer = readlineSync.question('Apakah Anda ingin melihat detail tempat wisata tertentu? (ya/tidak): ');
|
146
|
+
if (detailAnswer.toLowerCase() === 'ya') {
|
147
|
+
const placeName = readlineSync.question('Masukkan nama tempat wisata yang ingin dilihat detailnya: ');
|
148
|
+
displayPlaceDetails(filteredPlaces, placeName);
|
149
|
+
}
|
150
|
+
|
151
|
+
console.log('Terima kasih telah menggunakan aplikasi.');
|
152
|
+
};
|
153
|
+
|
154
|
+
// Memulai interaksi dengan pengguna
|
155
|
+
askCategory();
|
156
|
+
})
|
157
|
+
.catch(error => {
|
158
|
+
console.error('Error fetching data:', error);
|
159
|
+
});
|
package/package.json
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"name": "traveling.app",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"main": "index.js",
|
5
|
+
"scripts": {
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
7
|
+
},
|
8
|
+
"keywords": [],
|
9
|
+
"author": "",
|
10
|
+
"license": "ISC",
|
11
|
+
"description": "Aplikasi rekomendasi traveling menggunakan data dari berbagai situs web.",
|
12
|
+
"dependencies": {
|
13
|
+
"axios": "^1.6.8",
|
14
|
+
"js-yaml": "^4.1.0",
|
15
|
+
"readline-sync": "^1.4.10"
|
16
|
+
}
|
17
|
+
}
|
package/tea.yaml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# https://tea.xyz/what-is-this-file
|
2
|
+
version: 1.0.0
|
3
|
+
codeOwners:
|
4
|
+
- '0x2a8100F298100393E96632F3CcE1bae0e286e4Ac'
|
5
|
+
- '0x5302e62Ead6AA59eFE496Ad4824AD6f46d36a505'
|
6
|
+
- '0x6408294aEBcC05a4877d1a6AE0d38817536DAB14'
|
7
|
+
- '0x81c8e19C1c7aAfeAc6269d8052a22Fd995f2D576'
|
8
|
+
quorum: 1
|