var pointName, mapLat, mapLong, listingPoint, map, revDiv, impRevReq; function toggleMap(latitude,longitude,name) { toggle('mapSlideOpen','map'); if(!mapLat && !mapLong) { mapLat=latitude; mapLong=longitude; pointName = name; var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://maps.google.com/maps/api/js?sensor=false&async=2&callback=mapLoaded"; document.body.appendChild(script); } } function fetchImpRev(hID) { if(typeof(revDiv) == "undefined") { revDiv = document.getElementById('impRev'); url = '/hostelFetchImpReviews.php?id='+hID; impRevReq = new XMLHttpRequest(); impRevReq.onreadystatechange = fetchImpRevResp; try { impRevReq.open("GET", url, true); } catch (e) { alert(e); } impRevReq.send(null); } } function fetchImpRevResp() { if(impRevReq.readyState != 4) return; if(impRevReq.status == 200) { // OK response revDiv.innerHTML = impRevReq.responseText; } else { alert("Error: "+impRevReq.statusText); } } function mapLoaded() { listingPoint = new google.maps.LatLng(mapLat,mapLong); map = new google.maps.Map(document.getElementById("mapCanvas"), { zoom: 12, center: listingPoint, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: listingPoint, title: pointName, map: map }); } var dirDisplay, dirService; function mapAddMarker(lat,lon,name) { new google.maps.Marker({ position: new google.maps.LatLng(lat,lon), title: name, map: map }); } function mapDirections(lat,lon, isWalkable) { if(lat==0 && lon==0) { /* clear */ if(dirDisplay) dirDisplay.setMap(null); document.getElementById("mapDirections").innerHTML = ''; map.setCenter(listingPoint, 12); return; } if(!dirDisplay) { dirService = new google.maps.DirectionsService(); dirDisplay = new google.maps.DirectionsRenderer({ panel: document.getElementById("mapDirections")} ); } dirDisplay.setMap(map); dirService.route({ origin: new google.maps.LatLng(lat,lon), destination:listingPoint, travelMode: isWalkable?google.maps.DirectionsTravelMode.WALKING : google.maps.DirectionsTravelMode.DRIVING }, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { dirDisplay.setDirections(response); } }); }