How can I get the Latitude and Longitude of a ZIP Code? - php

I need some help to get the Latitude and Longitude dynamically of a ZIP Code entered by the user. so that i can work to show the shop address on those area of zip code.

Google is running some kind of geocoding, you should check it out, it might help you
http://code.google.com/apis/maps/documentation/geocoding/

http://code.google.com/apis/maps/documentation/geocoding/
There is some requirements for that like you have to register your google account for that but it's very easy and you have to pass some parameter which is describe at there.
You can make using JSON or XML as per your requirements.

You haven't specified what country you're looking to do this for but you can use the GeoNames API for postalCodeSearch.
For example (XML and JSON responses respectively)
http://api.geonames.org/postalCodeSearch?postalcode=90210&username=demo
http://api.geonames.org/postalCodeSearchJSON?postalcode=90210&username=demo

Going a little more in depth, you can get a JSON encoded object from google from the following url:
http://maps.googleapis.com/maps/api/geocode/json?address=ZIPCODE&sensor=false
just replace the ZIPCODE with the zipcode that you would like and it should return to you a json object with the latitude and longitude coordinates.

Related

Yahoo YQL geoCode not returning country in php

We are using Yahoo YQL geo code finder to find a country code using the latitude and longitude.
Following is the url used,
http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text+%3D+%2751.5073509%2C+-0.12775829999998223%27+and+gflags%3D%27R%27+&format=json
It used to work earlier, but suddenly it has stopped providing the country code.
Following is the result given,
{"query":{"count":0,"created":"2016-02-11T06:35:28Z","lang":"en-US","results":null}}
Please help me to find a solution for this.
Regards,
Neha
Checking the yahoo console. I can't find any reference for the table geo.placefinder
Are you sure that you are using the correct API and the correct parameter.
I have run a geo location query
select * from geo.places where text= "SFO"
http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.places+where+text+=+%27SFO
Which gives me the following result
{"query":{"count":1,"created":"2016-02-11T08:09:34Z","lang":"en-US","results":{"place":{"lang":"en-US","xmlns":"http://where.yahooapis.com/v1/schema.rng","yahoo":"http://www.yahooapis.com/v1/base.rng","uri":"http://where.yahooapis.com/v1/place/12521721","woeid":"12521721","placeTypeName":{"code":"14","content":"Airport"},"name":"San
Francisco International
Airport","country":{"code":"US","type":"Country","woeid":"23424977","content":"United
States"},"admin1":{"code":"US-CA","type":"State","woeid":"2347563","content":"California"},"admin2":{"code":"","type":"County","woeid":"12587707","content":"San
Francisco"},"admin3":null,"locality1":{"type":"Town","woeid":"2487956","content":"San
Francisco"},"locality2":null,"postal":{"type":"Zip
Code","woeid":"12797178","content":"94128"},"centroid":{"latitude":"37.62207","longitude":"-122.383659"},"boundingBox":{"southWest":{"latitude":"37.603939","longitude":"-122.403732"},"northEast":{"latitude":"37.64463","longitude":"-122.35482"}},"areaRank":"1","popRank":"1","timezone":{"type":"Time
Zone","woeid":"56043663","content":"America/Los_Angeles"}}}}}
Sorry for the hard format, I can't get the tags to work the way I want it.
https://developer.yahoo.com/yql/console/#h=SELECT+*+FROM+geo.places+WHERE+text%3D%2251.5073509%22
I have found a solution which works fine in my case.
The yahoo API service is unavailable for query format, hence I have used the below format.
http://gws2.maps.yahoo.com/findlocation?q=51.5073509%2C%20-0.12775829999998223&gflags=R&format=json
Regards,
Neha

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

is it possible to find geolocation using zipcode using PHP

Is it possible to find geolocation using zip code using PHP.
For example, if i am entering the zip code i need to find the name of that particular zipcode.
Is that possible? if yes kindly explain me how?
Thanks in advance
See the duplicate question on how to turn an address into coordinates using the Google Geocoding service.
A query in the format [zipcode], United States, e.g..
72116, United States
should always work for you.
Try maps.google.com to simulate the request.
The XML returned from the Google Service will contain the official place name, as well as other information like county and state names etc.
You can do this through Javascript and PHP using Google's Map API - check this question for an example of how this is used.
I dont think it can be done solely through PHP however because you'd need to access an API's data and they normally (not always) do this through javascript.
You should check the API documentation.
You can access the Geocoding API solely using PHP.. you don't even need an API Key anymore.
http://code.google.com/apis/maps/articles/phpsqlgeocode.html
So if understand this correctly, you want to know the City/State of the zip code you have entered?
Maybe you should look into the Access database here :
http://databases.about.com/od/access/a/zipcodedatabase.htm
And if you find it useful, just convert it into a MySQL table and use as you please.

How to get local time based on GPS coordinates?

My script has as input the latitude and longitude values as GPS coordinates.
How can I get the current local time?
Are out there solutions that do not use databases or web services?
PHP has a method to retrieve location based on a timezone, I am wondering if the reverse exists or not
geonames.org provide a range of webservices that can be used to get details from latitude and longitude. For example http://ws.geonames.org/timezone?lat=47.01&lng=10.2&style=full
You can just fetch that with your PHP code and parse the result.
See http://www.geonames.org/export/ws-overview.html for details of the available webservices.
Use this datafile. The data you are looking for is in zone.tab. wikipedia also has an overview of it - the table is generated from the datafiles.

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