Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

SOLVED type search with switch statement and google maps API

So I'm having a little trouble with a website I'm trying to build for coursework, basically I want to load a table with results based on a location search and then propagate the table with a list of hotels / bars / restaurants and switch between them using a button press which clears and refills the results table.

Problem being, all of the buttons load the results for hotels instead of their respective data types. Using console.log and reading similar questions I've narrowed down the problem to somewhere in the code snippet below, but just can't figure out why it's not switching to a different result. Any help would be greatly appreciated.

    function detectButton(btnSelected) {
    btnSelected = (this.id);

    switch (btnSelected) {

        case "#hotelBtn":
            btnSelected = 'hotel';
            break;

        case "#restaurantBtn":
            btnSelected = 'restaurant';
            break;

        case "#barBtn":
            btnSelected = 'bar';
            break;

        default:
            btnSelected = 'bar';
    }

    return btnSelected;
    }

    // When the user selects a city, get the place details for the city and
    // zoom the map in on the city.

    function onPlaceChanged(type) {
    var place = autocomplete.getPlace();
    type = detectButton(); 
    if (detectButton('hotel')) {
        place = autocomplete.getPlace();
        if (place.geometry) {
            map.panTo(place.geometry.location);
            map.setZoom(15);
            hotelSearch();
        }
        else {
            document.getElementById('search-bar').placeholder = 'Enter a city';
        }
    }
    else if (detectButton('restaurant')) {
        place = autocomplete.getPlace();
        if (place.geometry) {
            map.panTo(place.geometry.location);
            map.setZoom(15);
            restaurantSearch();
        }
        else {
            document.getElementById('search-bar').placeholder = 'Enter a city';
        }
    }
    else if (detectButton('bar')) {
        place = autocomplete.getPlace();
        if (place.geometry) {
            map.panTo(place.geometry.location);
            map.setZoom(15);
            barSearch();
        }
        else {
            document.getElementById('search-bar').placeholder = 'Enter a city';
        }
    }
}

Comments