Get total number of places using Google Maps API - php

I want to search some category of places supported from supported types like.. Getting Total number of museum in United States.
After reading these docs I found that we should do that search by this.
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
Even it shows the entire json..
I tried something like this
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=MYAPI
But How can I exactly get only total numbers of Museum available in United States.

There is no way to query the Places API for the total number of places that fall within a given radius in the Google database. When you query the Places API, the maximum number of results that will be returned is 20 (twenty) as described in this question/answers: What is the proper way to use the radius parameter in the Google Places API?.

Related

Incorrect results returned from a partial UK postcode

I am having an odd issue with Google Maps which their documentation doesn't seem to cover.
We have a page in our application that returns a list of engineer locations ordered by distance when an end user enters a postcode. We have recently noticed that some end users are entering partial UK postcodes (L1, BB7 or SE10).
These tend to be fine and work as intend but if the user searches for a partial postcode for the Manchester area they get odd results with distances of over 100 miles being returned.
I've researched this and it appears that Google is returning the locations for the motorway network where the road name matches the postal area in Manchester. For example: M4 is returning the motorway just north of Bristol instead of the city centre area.
The payload I am sending to Google is as follows:
$url="https://maps.google.com/maps/api/geocode/json?address={$address}&components=country:GB&key={$apikey}";
If I change the payload to this:
$url="https://maps.google.com/maps/api/geocode/json?components=country:GB|postal_code:{$address}&key={$apikey}";
I get ZERO_RESULTS from the API.
I saw this question from 2014 which is the identical issue but no resolution appears to have been found.
What am I doing wrong? Are there any workarounds that I could try to get slightly more accurate results? Am I better off restricting the inputs to full postcodes only?
I have come up with a rather messy hack that appears to solve my issue.
// Check if the postcode is a partial Mancunian postcode
if($postcode[0]==="M" && strlen($postcode) <= 4){
if($postcode[1]==6){
$manchester_postcode = "Salford ".$postcode;
}else{
$manchester_postcode = "Manchester ".$postcode;
}
$address=urlencode($manchester_postcode);
}else{
$address=urlencode($postcode);
}
$apikey=urlencode(env('GOOGLE_MAP_API'));
$url="https://maps.google.com/maps/api/geocode/json?address={$address}&components=country:GB&key={$apikey}";
If the postcode is identifiable as a partial (4 characters or less) and starts with the letter M, I prefix it with "Manchester". This solves all the mis-codings except for M6 which is still stubbornly selecting the motorway.
So I added in the check for the second character and change the prefix to "Salford". This resolves the problem.
For anyone else trying this solution you'll hit problems with the M60 postcode and some other random (non-Manchester) postcodes which route to equally random places (try E3 for example).
If you detect for any partial postcode and add 'postcode' after it (e.g. M60 postcode) it routes to the correct location.

Get zipcode in some radius of particular city of US

In my application, I want to get all the zip codes in some particular radius of a city of US. Now, I am trying to do like this find out the center of that city may be latitude and longitude and then get the zipcodes in the given radius.
Is there any other solution for this and any API suggestion to find zipcodes in given radius of a city ?
You can try the following approach, although I am not sure if it covers all possible postal codes:
Search the places of type postal office setting center location and some radius in the places API radar search.
E.g.
https://maps.googleapis.com/maps/api/place/radarsearch/json?location=32.2987573%2C-90.1848103&radius=20000&type=post_office&key=YOUR_API_KEY
This will give you place IDs of postal offices.
Execute reverse geocoding request for each place ID and extract a postal code from address components
E.g.
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJU2h85nfRKYYRwRVeeGrQ6lY&key=YOUR_API_KEY
Visually, it looks like

How to display the nearest cities using Google API?

I am developing a travel portal website.
Presently I am working on the destination module.here I need to display the nearest cities based on the places entered.
for example,If any one enter the name bangalore,The nearest cities around bangalore city should display.
I am searching for the google api to get the nearest cities around a place.
Can anyone help me to get the best api to display the nearest cities ??
Thanks In advance
This might be an alternative for you,
Another option:
Download the cities database from http://download.geonames.org/export/dump/
Add each city as a lat/long -> City mapping to a spatial index such as an R-Tree (some DBs also have the functionality)
Use nearest-neighbour search to find the closest city for any given point
Advantages:
Does not depend on aa external server to be available
Very fast (easily does thousands of lookups per second)
Disadvantages:
Not automatically up to date
Requires extra code if you want to distinguish the case where the nearest city is dozens of miles away
May give weird results near the poles and the international date line (though there aren't any cities in those places anyway

Is there any way to find country code from phone number In php?

I want to find country code from the phone number because phone number is without country code(which is my input) for instance my phone no is 9xxxxxxxxx and I get result that number is from India and it will display then +919xxxxxxxxx in php.Is there any way to find country code from phone number?
First you'd need a source for the data listing every country, its code and the number of digits and pattern of the number. Then you'd need to put that into an associative array, matching up each country with it's country code. Then you'd need a bunch of preg_matches using regular expressions to determine if the first digits plus the regular expression matched the country in the array. You've talking a huge project to program this from scratch.
You can build your own PHP function for a lookup like this, a list of all the Phone Netnumbers can be found on Wikipedia. If there is no net number it's not possible to track the country since countries can use the same phone numbers.

What's the metric num_queries in Google suggest

I use http://www.google.com/complete/search?output=toolbar&oe=utf8&hl=fr&q=test and i want to know num_queries for each keywords is the number of query for this per day, month, years ?
Do you know that ?
I verified that it's the total number of results that are returned for the search. You can see for yourself by plotting the autosuggest num_queries against the total number of results that are listed when you search google with that term. You'll find an extremely linear relationship.

Categories