Skip to content

Commit

Permalink
change city and fix location
Browse files Browse the repository at this point in the history
  • Loading branch information
tsolakoua committed May 5, 2023
1 parent 028b9c1 commit 1b036a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion amadeus_demo/amadeus_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
SECRET_KEY = ')-oaaz2gxfl6h7g$y6j5bw0519(a8^ue_^m=t5vnj)lbnp=cg&'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG_VALUE', True)
DEBUG = False
HOST_URL = os.environ.get('HOST_URL', 'localhost')
ALLOWED_HOSTS = ['localhost', '0.0.0.0', '127.0.0.1', HOST_URL]

Expand Down
2 changes: 0 additions & 2 deletions amadeus_demo/map/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def construct_activity(self):
activity_returned['link'] = self.activity['bookingLink']
activity_returned['lat'] = self.activity['geoCode']['latitude']
activity_returned['lng'] = self.activity['geoCode']['longitude']
activity_returned['price'] = self.activity['price']['amount']
activity_returned['currency'] = self.activity['price']['currencyCode']
except (TypeError, AttributeError, KeyError):
pass
return activity_returned
Expand Down
5 changes: 0 additions & 5 deletions amadeus_demo/map/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ def __init__(self, safety):
self.safety = safety

def construct_safety_scores(self):
overall = 1
overall_icon = 1
lgbtq = 1
theft = 1
medical = 1
try:
overall = self.safety[0]['safetyScores']['overall']
overall_icon = self.classify_overall_safety_score(overall)
Expand Down
30 changes: 17 additions & 13 deletions amadeus_demo/map/templates/map/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ <h2>Find the perfect hotel for your journey!</h2>

// Add a 'tap' event listener to the marker group
group.addEventListener('tap', function(evt) {

var clickedCoord = map.screenToGeo(evt.currentPointer.viewportX, evt.currentPointer.viewportY);
var clickedCoordLat = clickedCoord.lat;
var clickedCoordLng = clickedCoord.lng
// Use jQuery to make an AJAX request to a server-side Django view
$(document).ready(function() {
$.ajax({
method: 'POST',
url: "{% url 'search_safety'%}",
data: {
'hotel_lat': hotel_lat,
'hotel_lng': hotel_lng
'hotel_lat': clickedCoordLat.toString(),
'hotel_lng': clickedCoordLng.toString()
},
success: function(data) {
// Parse the JSON data returned from the server
Expand All @@ -78,8 +82,8 @@ <h2>Find the perfect hotel for your journey!</h2>
});
});
// Add POI and activity markers
addPOIMarker(map, hotel_lat, hotel_lng);
addActivityMarker(map, hotel_lat, hotel_lng);
addPOIMarker(map, clickedCoordLat, clickedCoordLng);
addActivityMarker(map, clickedCoordLat, clickedCoordLng);
}, false);

// Parse the JSON data containing information about hotels
Expand All @@ -104,14 +108,14 @@ <h2>Find the perfect hotel for your journey!</h2>
}
}

function addPOIMarker(map) {
function addPOIMarker(map, clickedCoordLat, clickedCoordLng) {
$(document).ready(function() {
$.ajax({
method: 'POST',
url: "{% url 'search_pois'%}",
data: {
'lat': hotel_lat,
'lng': hotel_lng
'lat': clickedCoordLat.toString(),
'lng': clickedCoordLng.toString()
},
success: function(data) {
var pois = JSON.parse(data);
Expand All @@ -122,7 +126,7 @@ <h2>Find the perfect hotel for your journey!</h2>
poi_lat = pois[i]['lat'];
poi_lng = pois[i]['lng'];
poi_category = pois[i]['category'];
if (poi_category == 'NIGHTLIFE') {
if (poi_category == 'NIGHTLIFE') {
var customIcon = new H.map.Icon("{% static 'icons/nightlife.svg' %}", {
size: {
w: 32,
Expand Down Expand Up @@ -183,14 +187,14 @@ <h2>Find the perfect hotel for your journey!</h2>
});

}
function addActivityMarker(map) {
function addActivityMarker(map, clickedCoordLat, clickedCoordLng) {
$(document).ready(function() {
$.ajax({
method: 'POST',
url: "{% url 'search_activity'%}",
data: {
'lat': hotel_lat,
'lng': hotel_lng
'lat': clickedCoordLat.toString(),
'lng': clickedCoordLng.toString()
},
success: function(data) {
var activities = JSON.parse(data);
Expand Down Expand Up @@ -246,8 +250,8 @@ <h2>Find the perfect hotel for your journey!</h2>
var map = new H.Map(document.getElementById('map'),
defaultLayers.vector.normal.map, {
center: {
lat: 37.773972,
lng: -122.431297
lat: 41.397158,
lng: 2.160873
},
zoom: 13,
pixelRatio: window.devicePixelRatio || 1
Expand Down
5 changes: 2 additions & 3 deletions amadeus_demo/map/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

amadeus = Client()


def hotels_map(request):
hotels = search_hotels('SFO')
hotels = search_hotels('BCN')
HERE_API_KEY = os.environ.get('HERE_API_KEY')
return render(request, 'map/map.html', {'hotels': json.dumps(hotels),
'here_api_key': HERE_API_KEY
Expand All @@ -24,7 +23,7 @@ def hotels_map(request):
def search_hotels(city_code):
hotels = amadeus.reference_data.locations.hotels.by_city.get(cityCode=city_code)
hotel_offers = []
for hotel in hotels.data:
for hotel in hotels.data[:15]:
list_offer = HotelList(hotel).construct_hotel_list()
hotel_offers.append(list_offer)
return hotel_offers
Expand Down

0 comments on commit 1b036a3

Please sign in to comment.