Google Maps Drawing Tools Api

How I (sort of) got around the Google Maps API results limit

image

Léna Faure Hacker Noon profile picture

A hardheaded object lesson of using closures in JavaScript

When I was looking for a job as a net developer a patc ago, I searched everywhere for a list of all the web agencies in Paris. I wanted to comparison every one of them and crawled the web for a careful and exhaustive list that I ne'er found.

Thusly I saw no other solution than to make it myself. I started wondering where those agencies could be referenced and accessed easy on the web, without getting lost in the 5+ million results of a google search.

Googles Places is a unspoilt way of determination businesses away keywords in any given area

I realized that nearly every web agency was referenced as a Place on Google Maps. And guess what ? Google Maps API, and more than specifically Google Places API, allows you to exercise all sorts of surprising things, including searching for places with a keywords filter, and fetching the place's name, along with its corresponding web site urls, photos and user ratings.

If I could retrieve a fashio to fetch as many results every bit possible for the Paris area victimisation Google Places, a great part of the job would be mechanically done, and save me a valuable amount of time.

Mollycoddler : I managed to get capable 186 results for the Paris area, which I know for a fact is not the total numerate of web agencies (several of them are not registered on Google Places, others simply don't appear in the results for unknown reasons), simply allowed Pine Tree State to find some engrossing results I wouldn't have establish otherwise. This is what it looks like :

The mapping:

Web agencies in Paris

The number (abridged):

Data fetched from Google Places

Google Places API seemed to have everything I needed for my purposes : once a search has been made and results are returned, the Aim Details request allows you to convey the key out, website uniform resource locator, photos and rating of each Place. I would have liked to equal able to evaluate the size of each government agency away number of employees, just hey.

Initiating the explore

I set up a labor along localhost (I would need to use PHP later to write the results in a file), and followed the JavaScript API documentation to enlightened the map (get it here) and make a Radar Search request (puzzle over it here) :

A School tex Look or a Nearby Search request would let you memory access right away the response parameters you need, but with one major limitation : they will return a maximum of 20 results per query. Each research can return as umpteen as 60 results, split across 3 pages, which way that you tooshie call a next_page_token data and grow a grand total of 60 results, but then you are perplexed.

Getting around the 60 results query terminal point

The Radar Search asking lets you look for for dormie to 200 places at once, but with less detail than is typically returned from a Text Hunt OR Nearby Search request. You basically sustain and ID for each place, but non a lot more details all but it, not even a name.

This means that you will have to iterate through your results to call the Place Details asking by departure the ID of each of the Places you found. The Place Details request is where all the parameters we facial expression for are returned.

This leave take place in the recall of our military service.radarSearch function:

This whole caboodle… partly. I only get 10 careful results by looping direct the results although the total number is 186. Wherefore is that ?

Acquiring around the 10 queries per endorsement limit : setTimeout and closures

Well, the problem with the Place Details request is that it lets you query just 10 results per second. The implementation of the code takes way to a lesser degree one endorse, and so information technology seems that we make a wall Here, doesn't it ?

What if we used the setTimeout function to query one result per second, therefore never reaching the limit of 10 results per secondment ?

The setTimeout function utilized inside a for cringle is a well-documented character of unexpected demeanour in JavaScript .

This is where the blockage will be of great help, allowing us to computer memory every value found throughout our 186 results and storing each of them in the agencies array for later use:

In the end, the booming JavaScript code snippet is :

I can nowadays use it to convey the results I want and use the data, and the lead is beautiful fun to watch :

Fetching one result / second

Naturally this would not work for a real-time application, simply for the resolve of fetching some information about particularised places I wanted to find, this worked alike a charm :)

Want to learn more about the basics of JavaScript? Check out my other articles:

  • Hoisting in JavaScript: a Quick Pass over
  • Read JavaScript Variable Scope with ease
  • Get your forefront round "this"
  • How to use JavaScript closures with trust
  • Grasp "By Evaluate" and "Past Reference" in JavaScript

I hope you enjoyed this clause, feel free to notice and like this article so that others can find it easily happening Average !

Tags

# javascript# google-maps# tech# api# first-remainder-development

Google Maps Drawing Tools Api

Source: https://hackernoon.com/how-i-sort-of-got-around-the-google-maps-api-results-limit-1c673e66ef36

0 Response to "Google Maps Drawing Tools Api"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel