"Find nearest location" by Zip/Postal Code? - php

I need a "find nearest location" on our website.
Where visitor enters their zip/postal code, then they are redirected to specific webpage for our nearest location. We have forty USA and Canada locations.
How can I build something like this? Could I do this with the Google Maps API? I already have a custom map on Google Maps. It's plotted with our locations. It would be nice to send Google Maps a command to say "what's our nearest location at ________ zip code".
Any suggestions?

if you have the longitudes and latitudes of each zipcode (search google) you can use the
Haversine Formula to calculate nearest neighbours.
http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe

You need a database of zip codes with longitude and latitude, from which you can calculate the distance.

Google Maps have restrictions in using is for business purposes, so you might want to consider those (restrictions) upfront.
From my former experience I would suggest MapQuest API. You can find details here:
http://developer.mapquest.com/ and some quick start guide here http://www.mapquest.com/features/developer_tools_oapi_quickstart
MapQuest seams to be better when it comes to commercial deals. Anyway, check their T&C before you will implement it in production.
They have JavaScriopt an I think regular WS for geo-location decoding.
Regards
Konrad

Related

Finding geology of a GPS location like in water or on a road

I am working on a project that I have array of GPS locations.
I want to know for each of those points, where are they?
I have a specific list that I am trying to match their location to one of those such as: Water, Highway, railway, ...
I tried this API (http://developers.cloudmade.com/wiki/geocoding-http-api/Documentation) but it doesn't give me any accurate data! even less than 50% correct!
Do you know any better solution?
I use php for server side that is responsible to gathering data from different webservices.
Our client sides are Android, Java
I expect system search and find the type of location automaticall
You don't give any hint of your platform (pc? smartphone? by hand? In automated program?)
But as a great starting point working with a few points by hand, in maps.google.com if you put the latitude and longitude (may be longitude and latitude try both) it will show them to you on the map. Google maps even has simple APIs so you can use this functionality reasonably simply (for example from a matlab program).

How do I calculate the driving distance between 2 places along with a map in php

I am looking for driving distance between two address/postcodes with displaying both on Google Map in php
I have search a lot of Scripts but most of them calculation distance only. I also want the both address along Google map also.
like this http://www.1stwebdesigner.com/wp-content/uploads/2010/06/distance-finder/source-distance-finder-google-maps.php
But this link calculate the "straight line distance" between two address and also show them on map
Please help me, i don't want straight line. I want driving calculation alone with map.(The script also show address on Google map)
You can do this with the API, I suggest you 'google' the google API for specifics, the documentation for google maps v3+ is awesome, you should have no problem if you're not reaching way outside your knowledge base.
and +1 #HeitorChang for that comment, I didn't see it.

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.

Calculating driving distance using zip codes

How can I code something which'll calculate the driving distance between 2 zip codes within the USA in PHP. An API or web service that has SOAP or REST will also do.
But I understand GoogleMaps API can't be used because it violates the TOS.. So I need a way without using Google Maps, because I have no intention of using their maps, just calculate the distance.
There isn't a whole lot out there that's free, other than Google Maps. The MapQuest API may give you what you need. Here's their guide to the service - it addresses getting driving distances/times between a set of points. Their terms of service don't appear to require that you display a map, but take a look and see if that meets your needs.
Google Maps Distance API has this exact Functionality. You can get a return as either xml or json.
Here is the documentation
https://developers.google.com/maps/documentation/distancematrix/
Here is a sample of the request url :
http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&sensor=false
One nice thing is you dont have to calculate the long/lat first

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