Location searching - php

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!

Related

Querying a MySQL database to show properties within a certain radius of a UK postcode using PHP

I have a MySQL table containing a list of properties in the UK. The table contains the full address of each property including the post code. I need to be able to query the database to show all properties within a certain radius (e.g. 3 miles) of a given post code.
I've searched SO and couldn't find a similar question.
Research on Google seems to suggest I need to use Google Maps but I can't find any material to get me going. I don't need to display the results on a map at this stage, a simple list of the properties will suffice.
I'm not asking for someone to code this for me (although that would be nice!), I'm just after a point in the right direction.
Thanks.
If your properties are already accounted on the Google Server the Google Places API would be able to retrieve them. You just need to set the radius of 3 miles as parameter.
https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
More details related to the parameter passed can be found in this official documentation.
If these places are not accounted in Google than they wont be displayed after requesting this REST API. Then you have to follow the standard procedure of:
Creating a query of fetching the requesting the address in within 3 miles with given postal address.
Select address from table where radius=3 & postalCode=xxxxx;
When you have the address convert them into Lat/Lng using Geocoder API.
Finally display them on Google Maps.
Hope this helps!!

Google Maps Geocode Issues: Certain Encoded URLs Failing

I am trying to get Lat/Lon for a list of locations from an address. It works for most addresses, but certain ones fail and return Zero Results.
Take this address as an example: 1045 Mono Way, Sonora, CA 95370
As you can see, that is a valid address on Google Maps - no issues there.
When pinging the Geocoder Api, I am encoding the address using urlencode(). This is the encoded address: 1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370
This is the link that I am accessing:
https://maps.googleapis.com/maps/api/geocode/xml?address=1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370&sensor=false
As you can see, zero results.
Now, if you change the first part of the address (1045) to any other number (e.g. 1044), you will get valid results.
I am lost.
Need help.
Please ;)
BTW, I am using this reply to get the lat/lon from the API: Google Maps - converting address to latitude & longitude - PHP backend?
I would bet that address just doesn't exist. The addresses are provided by local government, typically in a range of numbers that corresponds to a stretch of street. The fact that trying odd numbers doesn't work (1045, 1047, 1049) but even numbers do (1044, 1046, 1048) suggests that the addresses on one side of the road are not there. Or at least not in the dataset provided by the city or county.
The ideal solution would be a "fuzziness" argument to the API call, which would return a location similar to what their Maps site is. But since we can't rewrite third party APIs, I'd suggest checking for a "ZERO_RESULTS" response, and then resubmitting the request with just the street name if needed.
Also, you can do a geocode search without your API key, so you may want to keep that out of your question!

Is it possible to add an overlay in google maps api on user side e.g. with rmb click?

I'm working on a project of mine, which would require users to add markers on a google maps api map, that would be later on passed to a DB, which would store all overlay coordinates and once the map is loaded (in case the user has the required permissions, of course), a for loop will add all markers from the DB into the page and will visualize them (circles with static radius, but various coordinates). So long story short, I need a way to enable the users to put those markers themselves there and a way to read the LatLng coordinates and pass them to a script, which will flush them in the DB. One way (in case it's possible, of course) is to use the context menu and add an option like "set marker here", that would pass the coords to a function flushing them to the DB. Of course the workaround is RMB-> what is here, copy the coords and enter 'em in a input field, which almost inevitably will doom the project to an epic fail, because nobody will do that, but instead will just enter some random numbers, which would be moronic, because the project basically depends on those coordinates.
So is there a way to somehow automate the adding process of an overlay element in the api, that I could use? I googled around for a few days, tried to find something in the v3 help too, but didn't find anything really helpful so far..
Thanks in advance! All comments and help would be appreciated!
Cheers,
vlex

Get all the city names from the google maps - group by county

I'm trying to get a list of all the Hungarian city names from google maps, but I don't know how. Is this at all possible?
As far as I know, there is no such possibility. Although Google Maps API lets you determine the name of the location by its coordinates (the Reverse Geocoder API) and lets you find coordinates of places that match the given name query (the Geocoder API), I'm pretty sure that it won't let you get all objects that match a certain criteria.
So the short answer is: no, it's impossible.

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