API to get Center point zip code of a City - php

I am looking for an API that will give me all the zip codes within a 20 mile radius of a given US city. So far based on my online search, I could only find APIs that will give me all the zip codes with a 20 mile radius for a given zip code. Hence I’m trying to find an API that will (a) first find the zip code of the center point of a city, and then (b) use the API that I referred above to pass the zip code and the distance (e.g. 20 miles) to get all the zip codes within that 20 mile radius.
So I’m looking for (a) above, which is an API that will return the zip code of the center point of a city. This is all for US.

You can use the Google Geocoding API to get the location coordinates of a city, then use reverse geocoding to look up the actual zip code for that location.
Bear in mind if you get this data from Google you need to use it on a Google Map and are not supposed to use it outside of that.

Use the Geocoding API from Google to first map the city to the corresponding lat-long pair. Then use the Geonames API to get the postal codes in nearby radius. Use the following format for the Geonames API
http://api.geonames.org/findNearbyPostalCodes?lat=47&lng=9&username=demo
Find more details here

If you want a flat file instead, to maintain the data yourself, the USGS Gazetteer Populated Places file has really good city centroid coordinates and is free to use.

Related

Google Maps API area search

I have a set of adresses / coordinates. In my software the user should be able to search for a specific adress or coordinate and find the surrounding places of the set of coordinates in a specific radius. The results should be shown on a map.
(Mostly like Google Places for Restaurants just with my own set of places)
Displaying the places on a static map is not the problem, but handling the set of addresses (~5000) and calculating the distances to the place searched for.
How can I establish a function like this using Google's APIs?
Thanks!
You can use the harvesine formula and a bounding box. Or you can use a spatial index and a bounding box. The harvesine formula is used for spheres. Most likely you use straight distance (like the crow flies).

Find out if a given point is within the "area of polygon" - GoogleMaps API

I'm working on a web project where the idea is: users (A) can define an address each with the help of GoogleMaps API and with that i can get the coordenates and store them in database. Then other users (B) can design a polygon area on a map, again with GoogleMaps API, they would submit that area, and with that value the page would be able to find if there is any user (A) in that area.
How can i do it or where can i find information about this specific matter?
The Google Maps API v3 geometry library now includes the poly namespace, which has a containsLocation method:
containsLocation(point:LatLng, polygon:Polygon)
boolean
Computes whether the given point lies inside the specified polygon.
pass it a reference to the point and the polygon and it will tell you whether the polygon contains the point.
To compute the bounds of a polygon, iterate over the points in all its paths (can be simplified if you know it only has one path), adding them to a bounds object with google.maps.LatLngBounds.extend()

Drawing regional polygons on google maps v3 API

I need to draw complex regional bounding polygons in google maps. Is there a way to easily access regional data to draw these polygons? The regions will be australian postcode areas. If you type a post code into google (not maps normal search) such as "2454" into google the first result is an image with the regional polygon (perhaps this search only works if your searching from australia). Im assuming this data is accessible as google is drawing the polygon.
any idea how i would access this bounds data?
an example of what im talking about is here
http://maps.google.com.au/maps?pq=australian+postcode+2454&hl=en&cp=0&gs_id=2&xhr=t&q=2454&safe=off&gs_upl=&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&biw=1876&bih=872&um=1&ie=UTF-8&hq=&hnear=0x6b9e9f724b020f8d:0x1c0609b7ccd310d0,New+South+Wales+2454&gl=au&ei=a3MoT66iKoKuiQelk7m3Ag&sa=X&oi=geocode_result&ct=title&resnum=2&sqi=2&ved=0CDIQ8gEwAQ
This data isn't available through the Google Maps API at this time. You would need to find a 3rd party provider of the boundary data. A quick query shows several providers of the data, though I'm not sure if they're provided anywhere for free. Once you get the data, it's probably in a GIS data format, such as a Shapefile or a KML file. These can be loaded into Google Fusion Tables or KML files can be loaded directly using a Google Maps API KMLLayer.
That data is not accessible programmatically from Google. Your best bet is to either find KML for the data and then use either maps.google.com or the Google Maps API to load the KML (http://code.google.com/apis/maps/documentation/javascript/layers.html#KMLLayers) or to use somehing like Fusion Tables to load GIS data (or KML) into a fusion table, and then use the Fusion Tables layer in the Google Maps API (http://code.google.com/apis/maps/documentation/javascript/layers.html#FusionTables).
*Note that the Fusion Tables layer is experimental.

Calculate zipcodes in range

I have a website where users start by entering their zipcode.
I have a table with different shops which also contain the zip codes belonging to the shops.
Is it possible to get the zip codes within let's say a 5 km radius of the zip entered by the user?
So I can query the database and find all the shops near the user.
Can I use Google Maps for this? Should I get my hands on a pre-computed list of all zipcodes (single country) and their coordinates? Any other suggestions?
you can store longitude/latitude for each zipcode. That data is available for free on the net , one such is here http://www.boutell.com/zipcodes/. Then you would find the zipcodes in the radius by using great circle distance function which is discussed here MySQL Great Circle Distance (Haversine formula)
Google has a tutorial on this that should point you in the right direction. The bit of trigonometry in the SQL query is the only tough part. At first glance, there are basically two ways to go about this:
Get the lat/long coordinates for each store. You can do this using Google Maps' Geocoding API by providing the street address for the store. You'd only need to do this once for each location.
Only having the zip code for each store, and using a table of zip codes with geometrically-centered lat/long coordinates for each. Find the zip codes that are within range and then show the stores with those zip codes.
The first would be more accurate, but either works. If you're calculating distance from a zip code rather than an address, you'd still need to look up the lat/long coordinates for that zip code.
You'll need that latitude and longitude of each zipcode, and then use the Haversine Formula to get the approximate distance.
you need to get latitude/longtitude from the zipcode and then you can find places near by via maps or geoplaces api. head over to google maps api or YQL geo api.

Calculating in which country a coordinate is?

Is there somewhere a base of polylines for download, I need polylines of european countries and a solution in php for calculating in which country a certain coordinate resides.
I used google maps api for this till now but it's too slow and I make many requests frequently so I need to do this locally.
Using the Google Maps API is a good solution because the data is already there and you have the code to use it.
However, a local solution would be to setup a spatial database and load it with the appropriate data. For an open source solution I recommend PostGIS running on PostgreSQL. You then need to find and load in the relevant boundary data. Searching for "world political boundary shapefile" or "europe political boundary shapefile" will give you some useful links to check.

Categories