I have this java script in my html file....I have a keyword search in my webpage, and I want to pass the keyword search to the API. This is what I currently have: Not sure where I am going wrong that it is not producing any search results.
where I have
CNN
in the code, this is where my search variable should be passed...
<script type="text/javascript">
google.load('search', '1');
function OnLoad()
{
var customSearchControl = new google.search.CustomSearchControl('CNN');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_
CSE_RESULTSET);
customSearchControl.draw('cse');
customSearchControl.execute("$q");
}
google.setOnLoadCallback(OnLoad);
// tell the searcher to draw itself and tell it where to attach
// create a drawOptions object
var drawOptions = new google.search.DrawOptions();
// tell the searcher to draw itself in tabbed mode
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
searchControl.draw(document.getElementById("content"),drawOptions);
searchControl.addSearcher(new google.search.NewsSearch());
}
google.setOnLoadCallback(OnLoad);
</script>
You can use a third party solution like this one: https://serpapi.com/news-results
It works in a very similar way as the Google regular search, just pass the tbm=nws to your url.
https://serpapi.com/search.json?q=Trump&tbm=nws&location=Dallas&hl=en&gl=us
Results:
{
...
"news_results": [
{
"position": 1,
"title": "Trump blasts Sessions over indictments of two of his earliest ...",
"link": "https://www.cnn.com/2018/09/03/politics/donald-trump-jeff-sessions-justice-department/index.html",
"source": "CNN",
"date": "4 hours ago",
"snippet": "(CNN) President Donald Trump on Monday blasted his Attorney General Jeff Sessions and lamented the indictments of two lawmakers who ...",
"thumbnail": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSCv3eR2GkOR3WgDNTd4LqT77Bteu_ScA8NUFKcEYU1HskYXHXrnse-GnG0SN78_uUgM1k0nIQV"
},
{
"position": 2,
"title": "Trump accuses Sessions of hurting Republican congressional races",
"link": "https://www.reuters.com/article/us-usa-trump-sessions/trump-accuses-sessions-of-hurting-republican-congressional-races-idUSKCN1LJ231",
"source": "Reuters",
"date": "3 hours ago"
},
{
"position": 3,
"title": "Trump steams at Attorney General Jeff Sessions, reigniting his attacks",
"link": "https://abcnews.go.com/Politics/trump-steams-attorney-general-jeff-sessions-reigniting-attacks/story?id=57579418",
"source": "ABC News",
"date": "3 hours ago"
},
{
"position": 4,
"title": "Trump slams Sessions on Twitter, says AG is hurting GOP in midterms",
"link": "http://www.foxnews.com/politics/2018/09/03/trump-slams-sessions-on-twitter-says-ag-is-hurting-gop-in-midterms.html",
"source": "Fox News",
"date": "4 hours ago"
},
{
"position": 5,
"title": "Trump blasts Sessions over charges against GOP congressmen ...",
"link": "https://www.politico.com/story/2018/09/03/donald-trump-jeff-sessions-tweet-806298",
"source": "Politico",
"date": "5 hours ago"
},
...
],
...
}
I have the same issue and I think that the problem is these specialized CSEs have been 'deprecated' since 2010 ( see http://code.google.com/apis/websearch/) and now they just don't work. The new ones that do work are for general web search and image search. You can probably restrict the web search one to the CNN site if that's your goal. See What are the alternatives now that the Google web search API has been deprecated?
Related
I am making an api request in Alan studio and the news api returns an object from which I want to parse "articles" and store it and send them to my react code for displaying them on the news cards
But when I parse articles from the body, articles is becoming undefined.How can I JSON parse it?
Given below is the data returned from news api.
{
"status": "ok",
"totalResults": 10,
"articles": [
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Monkeypox: Nigeria bans bushmeat to prevent virus spread",
"description": "Experts say it is possible that the virus can be caught by eating meat from an infected animal.",
"url": "http://www.bbc.co.uk/news/world-africa-61676841",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/983B/production/_125017983_gettyimages-453645236.jpg",
"publishedAt": "2022-06-02T17:22:28.5473137Z",
"content": "By Chris EwokorBBC News, Abuja\r\nImage caption, Bushmeat is a delicacy in parts of Nigeria, but in other places it can be a vital source of food\r\nThe Nigerian government has banned the sale of bushmea… [+2373 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Ukraine war: Zelensky says Russia controls a fifth of Ukrainian territory",
"description": "Ukraine's president says Russia has taken 20% of Ukraine's territory, as the war nears its 100th day.",
"url": "http://www.bbc.co.uk/news/world-europe-61675915",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/130F7/production/_125017087_hi076131363.jpg",
"publishedAt": "2022-06-02T17:22:24.7575621Z",
"content": "By Matt MurphyBBC News\r\nImage caption, A Russian soldier in Mariupol\r\nUkraine's President Volodymyr Zelensky says that Russian forces have seized 20% of his country's territory, as Moscow's invasion … [+5338 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Oklahoma hospital shooting: Five dead after gunman targets physician",
"description": "Police say the man blamed the doctor for his back pain and had purchased a rifle only hours earlier.",
"url": "http://www.bbc.co.uk/news/world-us-canada-61676811",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/1307/production/_125017840_gettyimages-1241045718.jpg",
"publishedAt": "2022-06-02T16:52:23.4616839Z",
"content": "Image source, Getty Images\r\nImage caption, Police respond to the scene of Wednesday's shooting at St Francis Hospital\r\nPolice have said a gunman who killed three employees and a patient at an Oklahom… [+2376 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Canada says China 'buzzing' military flights in Asia",
"description": "Canada called the incidents are unprofessional and potentially hazardous to aircrew in the Pacific.",
"url": "http://www.bbc.co.uk/news/world-us-canada-61654043",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/75B3/production/_125013103_gettyimages-1341999649.jpg",
"publishedAt": "2022-06-02T13:37:19.2266278Z",
"content": "By Bernd Debusmann JrBBC News, Washington\r\nImage source, Getty Images\r\nImage caption, Chinese military aircraft at an airshow in September 2021\r\nCanadian military aircraft operating in Asia have been… [+2007 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Depp-Heard trial: Why Johnny Depp lost in the UK but won in the US",
"description": "Experts say key factors included having a jury trial and his lawyers using a specific legal tactic.",
"url": "http://www.bbc.co.uk/news/world-us-canada-61673676",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/6037/production/_125013642_gettyimages-1241024662.jpg",
"publishedAt": "2022-06-02T12:22:23.3055092Z",
"content": "By Robin Levinson-KingBBC News\r\nImage source, Getty Images\r\nIn 2020, Hollywood actor Johnny Depp lost a UK libel lawsuit against the Sun newspaper. But on Wednesday, he won a similar lawsuit against … [+2956 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Turkey wants be be called Türkiye in rebranding move",
"description": "The country wants to be called Türkiye as part of a rebranding campaign launched by its president.",
"url": "http://www.bbc.co.uk/news/world-europe-61671913",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/17CDD/production/_125010579_bluemosquegetty.jpg",
"publishedAt": "2022-06-02T11:07:25.2572035Z",
"content": "Image source, #MevlutCavusoglu\r\nImage caption, Turkish Foreign Minister Mevlut Cavusoglu\r\nTurkey will be known as Türkiye at the United Nations from now on, after it agreed to a formal request from A… [+1736 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Texas school shooting victim's parents mourn 'best friend'",
"description": "The parents of Alithia Ramirez say they want the world to remember their daughter through her art.",
"url": "http://www.bbc.co.uk/news/world-us-canada-61669234",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/11FC6/production/_125007637_p0cbl2cx.jpg",
"publishedAt": "2022-06-02T10:07:17.1192126Z",
"content": "Last week 10-year-old Alithia Ramirez was shot and killed when a gunman opened fire at her primary school in Uvalde, Texas. \r\nHer parents say they want the world to remember their daughter was good a… [+168 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Bill Cosby 'pounced' on teen in Playboy Mansion",
"description": "The comedian's lawyers dismiss the latest claim against him - stemming from 1975 - as a \"fabrication\".",
"url": "http://www.bbc.co.uk/news/world-us-canada-61664500",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/64DC/production/_125002852_gettyimages-1040552476.jpg",
"publishedAt": "2022-06-02T07:37:18.1596491Z",
"content": "Image source, Getty Images\r\nImage caption, Bill Cosby at his sentencing in Pennsylvania in 2018\r\nLess than a year after his sex assault conviction was thrown out and he walked free from prison, comed… [+2473 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Queen’s Platinum Jubilee: Trooping the Colour to begin celebrations",
"description": "The Queen's Birthday Parade will kick off four days of celebrating the monarch's 70-year reign.",
"url": "http://www.bbc.co.uk/news/live/uk-61516564",
"urlToImage": "https://m.files.bbci.co.uk/modules/bbc-morph-news-waf-page-meta/5.2.0/bbc_news_logo.png",
"publishedAt": "2022-06-02T06:07:24.9486456Z",
"content": "Trooping the Colour is an annual military parade that marks the Queens official birthday - which this year falls on 11 June (her actual birthday is 21 April).\r\nThis is a centuries-old tradition which… [+973 chars]"
},
{
"source": {
"id": "bbc-news",
"name": "BBC News"
},
"author": "BBC News",
"title": "Depp-Heard trial: Jury sides mostly with Depp in defamation case",
"description": "Jurors award Mr Depp $15m in compensatory and punitive damages, but also award Ms Heard $2m.",
"url": "http://www.bbc.co.uk/news/world-us-canada-61668780",
"urlToImage": "https://ichef.bbci.co.uk/news/1024/branded_news/12926/production/_125007067_tv076335814.jpg",
"publishedAt": "2022-06-02T01:37:20.4013741Z",
"content": "Media caption, Watch: Depp v Heard defamation case concludes in court\r\nA US jury has found Amber Heard defamed ex-husband Johnny Depp with an article in which she claimed she was a victim of domestic… [+4697 chars]"
}
]
}
// News by Source
intent('Give me the news from $(source* (.*))', (p) => {
let NEWS_API_URL = `https://newsapi.org/v2/top-headlines`;
if(p.source.value) {
NEWS_API_URL = `${NEWS_API_URL}?sources=${p.source.value.toLowerCase().split(" ").join('-')}&apiKey=${API_KEY}`;
}
api.request(NEWS_API_URL, (error, response, body) => {
const { articles } = JSON.parse(body);
console.log(articles); // returns undefined
if(articles?.length === 0) {
p.play('Sorry, please try searching for news from a different source');
return;
}
savedArticles = articles;
p.play({ command: 'newHeadlines', articles });
p.play(`Here are the (latest|recent) ${p.source.value}.`);
p.play('Would you like me to read the headlines?');
p.then(confirmation);
});
})
The problem here is the API request is expecting a promise to return from the API call, here is a quick code snippet that is working and returning data (just replace your API key in the URL.
// API CALL START HERE
let data = fetch("https://newsapi.org/v2/top-headlines?country=us&apiKey=<your api key here>")
.then(function(response) {
// This returns the promise from the API request which processes the data
return response.json();
})
.then(function(data) {
// Loop through the data returned for articles and console log each specific article
for (const article in data.articles ) {
console.log(data.articles[article]);
}
});
I am currently creating a simple website using HTML and JavaScript, but encountering a weird error. Essentially, the website has multiple html pages that display different genres of movies as recommendations. It displays the name, the billboard poster, and a quote retrieved from an open-sourced API found online.
All javascript functions for each of the movies are the same, so for example, the one for Toy Story is:
var getToyStory = function(){
var request = new XMLHttpRequest();
request.open("GET", "http://www.omdbapi.com/?apikey=8af1471b&t=Toy+Story", true);
request.onload = function(){
var data = JSON.parse(this.response);
var Plot = data.Plot;
document.getElementById("Plot").textContent=Plot;
};
request.send();
}
I know the javascript function is working because the error I encouted is in displaying it. I call the function using the follow tags:
<body onload="getToyStory()" id = 'Plot'></body>
When called, the HTML displays ONLY the one API quote and nothing else, and does it without any of the styling from the external CSS styling sheet. It doesn't report any errors in the console section of the Chrome Developer Tools, so I am unsure how to fix it.
When using the "onload" element it means that it calls that function one time once the DOM is loaded. The request sends back a string read in and parsed by you to JSON. The response looks like this:
JSON Response
{
"Title": "Toy Story",
"Year": "1995",
"Rated": "G",
"Released": "22 Nov 1995",
"Runtime": "81 min",
"Genre": "Animation, Adventure, Comedy",
"Director": "John Lasseter",
"Writer": "John Lasseter, Pete Docter, Andrew Stanton",
"Actors": "Tom Hanks, Tim Allen, Don Rickles",
"Plot": "A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy in a boy's room.",
"Language": "English",
"Country": "United States",
"Awards": "Nominated for 3 Oscars. 27 wins & 23 nominations total",
"Poster": "https://m.media-amazon.com/images/M/MV5BMDU2ZWJlMjktMTRhMy00ZTA5LWEzNDgtYmNmZTEwZTViZWJkXkEyXkFqcGdeQXVyNDQ2OTk4MzI#._V1_SX300.jpg",
"Ratings": [
{
"Source": "Internet Movie Database",
"Value": "8.3/10"
},
{
"Source": "Rotten Tomatoes",
"Value": "100%"
},
{
"Source": "Metacritic",
"Value": "95/100"
}
],
"Metascore": "95",
"imdbRating": "8.3",
"imdbVotes": "960,910",
"imdbID": "tt0114709",
"Type": "movie",
"DVD": "23 Mar 2010",
"BoxOffice": "$223,225,679",
"Production": "N/A",
"Website": "N/A",
"Response": "True"
}
You then create a variable to hold the "Plot" element from the JSON response making that a string that holds the following:
"A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy in a boy's room."
Whenever you use the following javascript function, "document.getElementById("Plot").textContent=Plot;", all this is doing is telling the element with id "Plot" (your HTML body) to load the text from the "Plot" variable as inner text inside the element. Essentially it looks like this in HTML:
<body id="Plot">
A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy in a boy's room.
</body>
If you want to add other HTML elements or CSS decorations to the page you would need to do that ahead of time then add the api response to the appropriate element (ie. <div id="Plot" class="awesome-css-stuff"></div>).
I want to get the newest 8 products depend on product's date. I can get the whole products array and filter it as you see below:
const newestProducts= [];
axios.get("http://localhost:3003/products").then(response => {
let products = response.data.sort(function(a, b) {
return new Date(b.date) - new Date(a.date);
});
newstProducts = product.slice(0,7)
});
but this will be so bad if I have thousands of product, and I just need to get the newest 8 Products only
I thought about adding ?_limit=8 to the call
axios.get("http://localhost:3003/products?_limit=8").then{...}
but this also doesn't work propersly as you know because it gets me the only top 8 products of the array
Is there any way to filter the products before I get it from the server or I MUST store them all in var and then filter them
The Json File
"categories": [
{
"id": 9,
"category": "bathroom",
"date": "2020/8/3",
"name": "ullam basin mixer",
"price": 160,
"img_1": "rim_mixer_01.jpg",
"img_2": "rim_mixer_02.jpg",
"rating": 4.5,
"description": "MARMO is a complete series made of 72 models, with different shapes and sizes for different functions, that keeps uncompromised its elegant beauty. This is a Demo Online Store."
},
{
"id": 10,
"category": "bathroom",
"date": "2020/8/19",
"name": "gravida bathtub",
"price": 2100,
"img_1": "inbani_bathtub_01.jpg",
"img_2": "inbani_bathtub_02.jpg",
"rating": 4,
"description": "A young company with a wealth of experience. created in 2004, inbani has evolved into a leader in innovation thanks to a conviction to create products which truly benefit the well-being of the customer. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 11,
"category": "bathroom",
"date": "2020/9/9",
"name": "vulputate mixer",
"price": 300,
"img_1": "marmo_mixer_01.jpg",
"img_2": "marmo_mixer_02.jpg",
"description": "MARMO is a complete series made of 72 models, with different shapes and sizes for different functions, that keeps uncompromised its elegant beauty. This is a Demo Online Store."
},
{
"id": 12,
"category": "bathroom",
"date": "2018/7/17",
"name": "aliquam veneatis bathtub",
"price": 2580,
"img_1": "sa_oche_01.jpg",
"img_2": "sa_oche_02.jpg",
"description": "Its oval, elliptical design with the incongruent walls invokes an avant-garde atmosphere in the bathroom."
},
{
"id": 13,
"category": "kitchen",
"date": "2020/3/13",
"name": "quisque teapot",
"price": 240,
"img_1": "theo_teapot_01.jpg",
"img_2": "theo_teapot_02.jpg",
"description": "Theo Teapot is a Scandinavian-Japanese teapot made from stoneware and bamboo, designed by Unit 10 Design for Stelton. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 14,
"category": "kitchen",
"date": "2020/2/12",
"name": "creamic teapot",
"price": 60,
"img_1": "cer_teapot_01.jpg",
"img_2": "cer_teapot_02.jpg",
"rating": 3.9,
"description": "Matte ceramic tea pot comes with integrated and removable metal tea infuser. Capacity 700 ml (2.96 cups). Dishwasher safe. This ceramic teapot has a white matte finish, coupled with a square shape and curved lines."
},
{
"id": 15,
"category": "kitchen",
"date": "2019/2/1",
"name": "bottle grinders",
"price": 30,
"img_1": "bottle_gringer_01.jpg",
"img_2": "bottle_gringer_02.jpg",
"rating": 4.8,
"description": "Bottle Grinders is a minimal, timeless salt and pepper mill set designed by Norm.Architects for Menu. Steering away from the predictable grinder, the Norm Bottle Grinder is not what you expect to see in a salt and pepper grinder. The form, shaped more like a bottle, cleverly tricks the user to encourage a more playful and experimental interaction with the product. This is a Demo Online Store. No orders shall be fulfilled. Purchase this product"
},
{
"id": 16,
"category": "lighting",
"date": "2020/1/3",
"name": "commodo blown lamp",
"price": 275,
"img_1": "tradition_blown_01.jpg",
"img_2": "tradition_blown_02.jpg",
"description": "Blown lamp SW3 & SW4 by &tradition is a mouth-blown pendant lamp with a quilted pattern, it comes in a translucent variant with a silver lustre or in a opal white version. Blown lamp is fitted with a powder-coated metal suspension. This is a Demo Online Store. No orders shall be fulfilled."
},
{
"id": 17,
"category": "lighting",
"date": "2020/6/9",
"name": "spot table",
"price": 100,
"img_1": "spot_lamp_01.jpg",
"img_2": "spot_lamp_02.jpg",
"rating": 3.4,
"description": "Set the stage. The Spot lamp is a lively, versatile addition to your room. This is a Demo Online Store. No orders shall be fulfilled."
}
]
The problem is not in API Calling... To enhance the performance you have to refractor the DATABASE REQUEST in the backend to get the last 8 products only.
Note:
You make this through the query you send to the database in the controller (ROUTE ) in the backend
I'll start out by saying that I am a pretty new web developer, so I apologize if this is overly basic... I just couldn't find it anywhere on Google. I'm receiving JSON data back from an API call to omdb, and I am unsure how to reference a line in the data Specifically, I am trying to reference the Rotten Tomatoes Value, and this needs to be repeatable for any movie I search. I started by storing the response in JSON and then working through each item I need:
var body = JSON.parse(body);
console.log("Title: " + body.Title);
console.log("Release Year: " + body.Year);
console.log("IMdB Rating: " + body.imdbRating);
console.log("Country: " + body.Country);
console.log("Language: " + body.Language);
console.log("Plot: " + body.Plot);
console.log("Actors: " + body.Actors);
console.log("Rotten Tomatoes Rating: " + body.Ratings.????RottenTomatoes???);
It's just the Rotten Tomatoes Value Line I can't figure out! Everything else works. To clarify, this is just a JSON referencing issue I cannot figure out.
{
"Title": "Anastasia",
"Year": "1997",
"Rated": "G",
"Released": "21 Nov 1997",
"Runtime": "94 min",
"Genre": "Animation, Adventure, Drama",
"Director": "Don Bluth, Gary Goldman",
"Writer": "Susan Gauthier (screenplay), Bruce Graham (screenplay), Bob Tzudiker (screenplay), Noni White (screenplay), Eric Tuchman (animation adaptation)",
"Actors": "Meg Ryan, John Cusack, Kelsey Grammer, Christopher Lloyd",
"Plot": "The last surviving child of the Russian Royal Family joins two con men to reunite with her grandmother, the Dowager Empress, while the undead Rasputin seeks her death.",
"Language": "English, Russian, French",
"Country": "USA",
"Awards": "Nominated for 2 Oscars. Another 10 wins & 21 nominations.",
"Poster": "https:\/\/images-na.ssl-images-amazon.com\/images\/M\/MV5BNGJiNWFlYTMtZTBiZi00ZTVmLWJmZmMtNzEzYzZjNzYzZmRmXkEyXkFqcGdeQXVyNTA4NzY1MzY#._V1_SX300.jpg",
"Ratings": [
{
"Source": "Internet Movie Database",
"Value": "7.1\/10"
},
{
"Source": "Rotten Tomatoes",
"Value": "85%"
},
{
"Source": "Metacritic",
"Value": "59\/100"
}
],
"Metascore": "59",
"imdbRating": "7.1",
"imdbVotes": "94,074",
"imdbID": "tt0118617",
"Type": "movie",
"DVD": "16 Nov 1999",
"BoxOffice": "N\/A",
"Production": "20th Century Fox",
"Website": "N\/A",
"Response": "True"
}
The Rotten tomatoes value is in the 3rd element of the array. Array indexes start at 0. Therefore, what you need is body.Ratings[2].Value.
If the order of the Ratings array is unpredictable, use filter function as below.
//If the order of the source array is unpredictable
//use filter
var rtValue = body.Ratings.filter(function(source) {
return source.Source === "Rotten Tomatoes";
}).Value;
That's because it is an array inside an object. body.Ratings[0]. You are referencing the spot of an array. Definitely look into arrays.
"Ratings": [ { "Source": "Internet Movie Database", "Value": "7.1/10" }, { "Source": "Rotten Tomatoes", "Value": "85%" }, { "Source": "Metacritic", "Value": "59/100" } ]
See the [ square brackets ] Each object inside {} can be referenced with an integer inside [0], [1] etc.
Look at some online tutorials. www.w3schools.com/js is a great place to start
Is there any google/Yahoo/Bing API which gives local business results based on a ZIP/GeoCode of a location? If yes, please let me know.
If Google Maps has such service, please let me know what where do I get a reference regarding that?
Disclosure: I work at SerpApi.
Is there any google/Yahoo/Bing API which gives local business results based on a ZIP/GeoCode of a location?
Yes, you can use SerpApi to get local business results based on ZIP, query, or GPS coordinates: https://serpapi.com/playground?engine=google_maps&q=coffee+Austin+TX+78747&type=search
Sample response
{
"local_results": [
{
"position": 1,
"title": "The Standard Grill",
"data_id": "0x89c259c06677ef37:0x5707f22fe7137aa2",
"gps_coordinates": {
"latitude": 40.7406697,
"longitude": -74.0079042
},
"place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259c06677ef37%3A0x5707f22fe7137aa2%218m2%213d40.7406697%214d-74.0079042&engine=google_maps&google_domain=google.com&token=f01cbc346c0db944&type=place",
"rating": 4.1,
"reviews": 840,
"price": "$$$",
"type": "Bar & grill",
"address": "848 Washington St, New York, NY 10014",
"hours": "Open until 11:30 PM",
"phone": "(212) 645-4100",
"website": "http://www.thestandardgrill.com/",
"description": "Trendy, upscale American dining. Trendy, clubby, hotel-set American bistro under the High Line with sidewalk tables & lively bar.",
"editorial_reviews": {
"summary": "Where To Eat On Christmas Day In New York City",
"link": "https://www.forbes.com/sites/melissakravitz/2019/12/13/christmas-dinner-new-york-city/"
},
"thumbnail": "https://lh5.googleusercontent.com/p/AF1QipMGM_4u4iQcrdRZApFFIinDga-cb0rXu79aFxvv=w125-h92-k-no"
},
{
"position": 2,
"title": "Rockmeisha - Sake & Grill",
"data_id": "0x89c259938c3a05cb:0xa1b2fe3b945a853d",
"gps_coordinates": {
"latitude": 40.732638,
"longitude": -74.00237299999999
},
"place_id_search": "https://serpapi.com/search.json?data=%214m5%213m4%211s0x89c259938c3a05cb%3A0xa1b2fe3b945a853d%218m2%213d40.732638%214d-74.00237299999999&engine=google_maps&google_domain=google.com&token=8bcfdeb90a3d1f1a&type=place",
"rating": 4.3,
"reviews": 102,
"price": "$$",
"type": "Tapas restaurant",
"address": "11 Barrow St, New York, NY 10014",
"hours": "Opens at 6:00 PM",
"phone": "(212) 675-7775",
"website": "http://rockmeisha-izakaya.business.site/",
"description": "Japanese drink-&-snack joint. Traditional Japanese drinking establishment pairing its sake & beer with ramen & small plates.",
"editorial_reviews": {
"summary": "25 Exemplary Fried Chicken Dishes Around NYC",
"link": "https://ny.eater.com/maps/nyc-fried-chicken-best"
},
"thumbnail": "https://lh5.googleusercontent.com/p/AF1QipNA8eJZ-VZxHIV43490yYZCnjDbBbYUA9wiH_Lq=w122-h92-k-no"
}
]
}
You can use Node.js wrapper
const { GoogleSearchResults } = require('google-search-results-nodejs')
const client = new GoogleSearchResults("API_KEY")
const parameters = {
engine: "google_maps",
type: "search",
google_domain: "google.com",
q: "NY 10014 grill",
};
function onResponse(data) {
console.log(data.local_results[0])
}
client.json(parameters, onResponse)
If Google Maps has such service, please let me know what where do I get a reference regarding that?
https://serpapi.com/maps-local-results
Google does have that, you can even check few sample implementations:
http://code.google.com/apis/ajaxsearch/local.html