Google Places API search for a PLace in GLOBE - php

I want the user to enter a name of a place, and it will return all the matching places, User will select one from the list, In Google Place API I need to provide a lat, lng and search within a certain radius.
But I want no radius, rather I want it to search the globe, much like the place search in Google Earth.
Right now I am planning to observe Google Earth under wireshark and I'll repeat the same. Is that lawsuit ? or is there any other straight way to do the same ?
I've no problem in using services like bing or any others, if they offer the same

Have you thought about entering a lat,lng of 0,0 and a radius of 12,500 miles? That should cover the world.

Related

Calculating distance between two post codes

I would like some help with how to go about calculating the distance between two post codes. Here is the setup that I wish to have, let me give you a scenario.
A user logs into my website (they have provided their details, their postcode being one of them). That data is stored in the users table.
I have another table with details about locations. I would like to display locations (and the distance) that are closest to the user.
I know that there are certain methods that can be used, for example:
Converting a postcode to a long-lat and using built in methods to calculate the distance, I think Google offer a free service. But I have no idea how I would implement such a thing. All the tutorials I have taken a look at seem too complicated and for the time being I want a very crude and simple solution upon which I can build and more importantly learn!
I am fairly familiar with PHP and MySQL when it comes to basic input/output of data. But I am not sure of the best way to handle the information with regards to user data, and the locations of the 'businesses'.
Any suggestions, comments will be more than appreciated.
If you're US based, this API should meet your needs: https://www.zipcodeapi.com
It's made specifically to find distance between two zip codes, tells you the long-lat for zip codes, find all zips relative to a location, etc.
Get postcode northings eastings data free from ordinance survey (credit them on your webpage to get free)
2 calculate distance from the appropriate csv flat file (M.csv contains all manchester postcodes and north and eastness).
Distance is sqrt((n1-n2)**2 +(e1-e2)**2) - excuse my fortran
If its slow,and you want an approximate distance create a small database of first half postcodes averages so you are looking up M20 not M20 3nb.
5 NB google don't like you using their postcode apis outside google Maps.
I am wondering about an algorithm so that for short distances, if you are looking at places close to a postcode, you just search M postcodes for a M postcode (and maybe nearby post areas like SK, OL, if you have a table of adjacent postcode areas).
7 Any body taken this further?

Postcode Radius Validation

I need to offer user's who Live in x location in the UK.
I'm currently having users enter their postcode via a form I've built, the postcodes get submitted to the database and I use Google search to check their in a close proximity to which I can offer services.
This sometimes can take me hours to manually hack through hundreds of postcodes this way so I'm looking to automate the process; if I could have the postcodes run through a script that'll determine if postcode x is within y miles of postcode z I'll be able to die happy.
Speed is also an issue for me, so I'm looking for a solution that doesn't rely on an external web service. Does anyone know of a script that'll do the trick?
What I would do is map postcodes to latitude and longitude and then use the distance formula between lat/lon coordinates to find out how far away they are.
Link for formula: http://www.mathforum.com/library/drmath/view/51711.html
Link for postcode -> lat/long values: http://www.freemaptools.com/download-uk-postcode-lat-lng.htm (this should be okay but haven't checked)

How should I make the "close to".. "near by"

I would like to make add a feature to my search field.
So you can write Close to: Copenhagen (example).
It should then take like 5 km range around /inside Copenhagen (copenhagen is capital of denmark), and get the addresses that are within, and show them as results..
So it takes all addresses, checks if they are within 5 km range around copenhagen and then display those that are.
Is this possible to do? If not, any simliar ways to do this? What should i look into?
You can use (for example) the Google Maps API to geocode a text description of a location (the search term, and the addresses) into a GPS coordinate location. You then check which of the locations in your database is within range of the search term location. The terms and conditions of the use of that API require you to use the geocoding results to display a Google Map though.
Determining "within range" efficiently might be tricky though, you generally want either a GIS-capable database to do the calculations for you. A hackish shortcut that's easy to implement over any DB is taking the points 5 kilometers (or whatever distance you want) north, east, south, and west of the search term location, and then looking for addresses that have latitudes and longitudes between the minimum and maximum latitudes and longitudes that gives you. This page lists what the required formulas are. (This approach will not work if the searched area is near where longitude "wraps around" and doesn't search a rectangle because of the curvature of the earth, but not many people search for restaurant reviews or what have you in the Arctic or the middle of the Pacific.)
You should look at geocoding.
One way to do that is to use the Google Maps API, it allows you to convert an address into coordinates and from those you can easily calculate addresses that are within a certain distance.
Take a look at:
http://code.google.com/apis/maps/documentation/webservices/index.html
I'm sure that if you look for "geocoding" you will find many other solutions, if you don't like this particular one.

Location searching

For the site I am building I want the user to be able to search for a location, however because I don't have a list of locations for the UK, I have developed a script in PHP which calls: http://ajax.googleapis.com/ajax/services/search/local in order to get the lat and lon coordinates of this location to store in the database for future use.
This works well apart from if I search for a town, for example Heaton, it brings back the one in Staffordshire rather than the one in Newcastle for example.
The whole reason I'm using the google ajax api is to cut down the google requests per day because I don't want to exceed the daily request limit.
As you can see though, I've hit a brick wall because the search isn't refined enough to bring back the correct location.
Can anyone suggest another way around this? I'm quite stuck. Thanks
I don't know if you have seen this already, but there is a parameter in the Google Search API that allows you to specify a boundary for the search:
GeocoderRequest object specification
The specification for a geocoding
request to be sent to the Geocoder.
Properties Type Description
address string Address. Optional.
bounds LatLngBounds LatLngBounds within which to search. Optional.
language string Preferred language for results. Optional.
location LatLng LatLng about which to search. Optional.
region string Country code top-level domain within which to search.
In your case I would specify a bounds around northumberland, so something like:
http://ajax.googleapis.com/ajax/services/search/local?q=heaton&v=3.1&region=GB&sensor=false&bounds=(55.395,%20-2.510%20,2054.342,%20-0.417)
might work...? I don't know if this would be relevant to your app though. Good luck!

google Maps getDistance without loading the page

Google maps has a function that lets you retreive the distance between two points: getDistance(), of the GDirections class.
Now, this is Javascript, so it'll only be able to calculate once the page has loaded.
My search form however, has the ability to indicate what's the maximum distance you want between yourself and another person and based on that, a list of search results has to be provided.
Since I can't use this function in PHP, is there another way for me to calculate the distance between 2 points on the earth? By giving up the street, postal code and city name, just like what Google maps needs.
This page has a list of google maps parameters for use in http connection. By specifying the output paramter you can choose to give back kml files or similar and can be used in any lanuage that can make http connections.
Looks like you want to calculate a Great Circle Distance
Formulas have been discussed here on stackoverflow before.
A point on earth is defined by it's latitude and longitude. If you want to calculate the distance between 2 points on earth by giving up the street, postal code and city name, you will need geo-referene data.
This data is available for free on the internet, but the accuracy and availability differ greatly from region to region. (USA data is of good quality, data for Kenia for example will be harder to come by)
So to answer your question:
Yes, there are other ways to calculate what you want. But they require more work/are more complex than just querying the google API.
You might want tot read: Creating a Store Locator with PHP, MySQL & Google Maps
Hope this points you into the right direction.
You can use kml file. It's xml-formatted file that you can recieve by link like http://maps.google.com/maps?f=d&hl=en&saddr=<src latitude>,<src longitude>&daddr=<dist latitude>,<dist longitude>&ie=UTF8&0&om=0&output=kml
in recieved file you can parse and summate distances from

Categories