rockchalkwushock
rockchalkwushock

Reputation: 1273

Google Places Detail Filtering Results

I'm using the Google Maps JS API along with that I am using the geolocation feature and the Places Library. This just started occurring in the last 24 hrs where when the geolocation is calculated and then the code searches for the nearby breweries I get lots of random things (not just me though have had other's test the issue in there regions of the USA). McDonald's doesn't serve beer last I checked! I looked back and have not made changes to any of the code that manages this so I'm scratching my head on what is going on.

Google does not have 'breweries' as a type so I am using the keyword property and the value to be searched is 'breweries'. I even tried looking for 'brewery' & 'brewing' since the actual breweries in my city use either one of this in it's name. This tactic actually made things worse. I tried finding a correlation between the actual breweries and the type[] property but no luck. Most elements in the type property return as bar, restaurant, establishment, point-of-interest.

So what I'm wanting to know: is there a method for taking a string say 'River City Brewing Co.' and searching it for a specific string value 'brewery' and 'brewing'. I'm trying to find a way to filter the result since either my code (most likely) or Google is drunk when searching for results for local breweries.

So code wise I'd want to try and do something like:

function filter(search_results)
{
    if(brewery_data.name ??? 'brewery' || 'brewing')
    {
        // send to results
        return true;
    {
    else
    {
        // reject
        return false;
    }
}

Does anyone have any suggestions or ideas on how to do that? I've left a link to the code on my GH page for review. Maps.js contains all of the mapping functionality right now and app.js is the main script all others are kind of storage at the moment and not called by index.html. I appreciate the help because this is really stumping me on how to beat this bug. If I've missed something in the Google code that is causing this I'd much rather fix that but ultimately I have to find a way to filter the results to make my app work properly and not send my user to McDonalds for a Big Mac and IPA!

Code: https://github.com/rockchalkwushock/Bro2Brew_App/tree/staging Web App: https://rockchalkwushock.github.io/Bro2Brew_App/

Upvotes: 0

Views: 578

Answers (1)

rockchalkwushock
rockchalkwushock

Reputation: 1273

Never did figure out why I was getting so many oddball results returning for keyword: 'breweries' but I found a way to filter the results with the toString.prototype.includes(). You can see how I used it below. If anyone has a better way to go about filtering or knows why I was getting back results that were way off the mark from my keyword property please feel free to share!

function callbackResults(results, status)
{
  if (status == google.maps.places.PlacesServiceStatus.OK)
  {
    for (var i = 0; i < results.length; i++)
    {
      var place = results[i];
      var placeid = place.place_id;
      var name = place.name;

      if (name.includes("Brewery") || name.includes("Brewing"))
      {
        // console.log(name);
        apiMarkerCreate(place.geometry.location, place);
        addPlaceDetails(placeid);
      }
    }
    return true;
  }
  else
  {
      return false;
  }
}

Upvotes: 1

Related Questions