Get zip code from latitude, longitude? - iphone

I want to get zip code from users current location(Latitude, Longitude), I had used MKReverse Geocoder delegate methods, but sometimes I am not able to get zip code information based on latitude & longitude (valid values). Are there any other alternatives for MKReverseGeocoder ? ZipCode database are specific to countries, that's why I don't want to use them. Any other idea or clue?
Thanks

Consider the GeoNames web service. It's a complete geocoding/reverse geocoding suite under a Creative Commons attribution license. You can either download their data, or hit their web service. The best thing is, they don't require any API keys or licensing silliness--you just hit their web app and bang you got data.
Here's an example: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=36&lng=-79.08 That'll return you a JSON object for the zip codes around the Chapel Hill, NC area.
It's also international. Here's Seaford, England, and the only difference is the lat/lng pair I'm sending: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=50.5&lng=0.08
Then you need to learn to make web requests and parse JSON (if you don't already have a grip on those things), and you're all set.

This is actually a tricky question. Using a geocoding solution like GeoNames is likely to lead to major errors for a lot of queries. The reason for this is that GeoNames by looking up the record in their database that is closest to your query point and then returning the ZIP code they have on record for that point. This works great when your query point is right on top of a record in their database, but can lead to errors otherwise. For example, if their nearest record is a few blocks away in a different ZIP code, you'll get the wrong answer.
The US Census Bureau has created maps of the ZIP codes:
https://www.census.gov/geo/reference/zctas.html
Please see their notes on that page.
I have also worked on a project that uses the Census maps to provide an API that gives back the ZIP code for a given latitude and longitude. It is at:
http://askgeo.com
We offer both a web API and a Java Library that you can run on your own server. The library has excellent performance. Since our site offers additional information than just the ZIP code, you can read about our ZIP code service here:
http://askgeo.com/database/UsZcta2010
And you read about the documentation for the Web API here:
http://askgeo.com/#web-api
The GeoNames methodology is fundamentally flawed for this type of query. If you are looking for the polygon that contains a given query point, you need a map with the polygons, and you need a spatial index to provide fast look-ups. GeoNames has neither. AskGeo has both.

If you have a free db (available from that site? Just search for zip code database and you'll see it)
then you can run an internal SQL query testing for nearby lat/longs. That way you won't need to worry about licensing a web service.
You have three options then. SQL BETWEEN statement, the hypotenuse equation, or Haversine. Haversine being the best, luckily it's tutorial'd elsewhere

EDIT:
Couple of other options I've seen recently:
http://developer.yahoo.com/geo/placefinder/guide/index.html
http://jamiethompson.co.uk/projects/2010/04/30/an-open-free-uk-postcode-geocoding-web-service/
http://www.postcodeanywhere.co.uk/geocoding-service/api.aspx
--
Take a look at the Google Maps API - Reverse Geocoding (only useful if embedding results in a Google Maps interface).

Sample code here:
Get Zipcode from results[1].formatted_address
https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse

Related

How to use overpass api?

I am a total newbie so this may be a silly question, but I can't find any tutorials on how to query overpass api to display things on own website. Do I install it on my server or is there a code to query it in the script?
What I want to achieve is to have a searchbar on one page to search for tags, and that would display one random point with that tag on the other page with a leaflet map.
But I am struggling to even display any points on it. Would it be actually better to have a local geojson file with set list of points in one town if I want to limit them to just this town anyway?
I will be grateful for any help, it's a first time I am doing something like this and it horribly stresses me out
You can visually run and try overpass queries using http://overpass-turbo.eu/.
In order to unload the overpass server, it would be a good idea to fetch the data once (and update regularly) and host them on your own server (also pay attention to the terms of use of the specific APIs, they might limit the number of requests per hour or prohibit using the for autocomplete).
To query the server from an application, GET from https://overpass-api.de/api/interpreter?data=, followed by your request (the same you would type into overpass turbo, just without line breaks).
It is also possible to host an overpass instance on your own.
If you need to learn the Overpass Query Syntax first, you can read the docs.

reverse geocoding on the IPhone - getting exact street numbers

We are building a series of applications for the IPhone (IOS5), where we use reverse geocoding. Most of the time, CLGeocoder returns a range for the address number (eg. "someaddress 2-5"). We want to retrieve the exact street number for every reverse geocoding request.
As I have come to understand, this is not controlled by me as a developer but rather by Apple, which makes a call to Google and returns the results (the range of street numbers). Has anybody else encountered the same problem and found a solution?
One solution I was advised to do is purchase the google maps API for business. In its documentation it states that it offers "advanced geocoding", but no details are given for reverse geocoding and street numbers. Has anybody had any experience with this API?
Another thing that comes in mind is to use some third-party service that does reverse geocoding. But the thing I am not sure is if Apple will accept it. Does anybody has to suggest a third-party service that does reverse geocoding and returns the exact street number for a given position on the map?
Thank you in advance
It looks like GeoNames would fit your needs well.
From the Wikipedia page:
GeoNames is a geographical database available and accessible through
various Web services, under a Creative Commons attribution license.
I myself have been using CLGeocoder, and haven't experienced any issues with it returning a range of street numbers.

Extract map information from Bing Maps

I would like to write a navigation software for windows phone 7 that is available without being on the internet. Therefore, I would like to download the map information from Bing maps. Not the entire world or country, just a small city - because this software is just for me and I only need navigation within my home town.
What I basically need is something similar to the map export that OpenStreetMap offers. I could not find anything equivalent on bing maps, so I wrote a program that queries bing maps (through the API) for routes. It then saves intersections and thus builds a graph. This technically works and I get a lot of streets, but sometimes bing leaves out a single intersection. In that case, my data will become invalid.
So I was wondering if there is any way of asking the API directly for a map export, returning something like an array of streets that is within a certain boundary rectangle. (Or something similar)
Thanks for your help
No, there is no standard API call in Bing Maps API that will let you do this.
Downloading all the street data within "a small city" would violate the terms of service. See 8.2(r) at http://www.microsoft.com/maps/product/terms.html.
If you want that data, you can try OpenStreetMap or else you would probably have to license the data from a commercial provider of such things which is no doubt very expensive.

List / database of valid addresses for geolocation / geospatial testing

I'm running some geospatial tests to demonstrate use of the MongoDB geo APIs. The problem is that I don't have a list of valid addresses with which I can test.
The idea is to query the latitude and longitude through Bing Maps as my sample application is a job search website where the locations I will be indexing to query against would be entered as listing for new job opportunities and would be entered using addresses rather than latitude and longitude coordinates.
Any help would be much appreciated!
I don't suspect Microsoft provides a list of fake locations that will register to valid lat/long coordinates on Bing (for this exact purpose or similar), but if they do...that would be equally acceptable.
FWIW, I did thoroughly check Microsoft's documentation and found nothing on this.
Alternatively, I could just query common places like Starbuck's or POI's (probably what I'll end up doing), but it would be nicer if there were a testing mode where you could use addresses that would register with Bing. Microsoft, in case you happen to subscribe to Stack Overflow tags, I would post this suggestion on the Bing community forums but there is no way to post an answer or question there, please fix this.
Decided just to use the Bing Maps API to query some popular companies although this is not ideal.

How to find the long and lat of a city on the iphone?

I am trying to find the long and lat of a city on the iphone. Say the user is searching for London, I would call some function that would retrieve the long and lat of London. I have looked on the web and found you can use a Google API but there must be an Apple function somewhere to handle this?
I have come accross the MKReverseGeocoder which takes the long and lat and tells you what city you are near. e.g.
// reverse geocode the user location
geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
If it can reverse the process there must be some form of MKGeocoder class?
but there must be an Apple function somewhere to handle this
Why must there be? Because there isn't.
There are a number of web services you can use (e.g. Google) or you could download a place name database such as http://www.geonames.org/ and import it into your app. It's probably best to import it into an SQL database which you can then search from your app.
See OpenStreetMap. It gives you more flexibility in accessing its data. You could pre-populate a CoreData store with the informations you need.
There are some api-clients, i.e. route-me or cloudmade.
The iOS5 SDK has added support for both forward and reverse geocoding. Take a look at at the CLGeocoder class class for more info.
First, give up that there "must be" an Apple way. There really isn't. If you don't believe me and my nearly 2k of experience points, listen to Ole and his 13k.
There are three services I've seen.
I tried Google's geocoding API. It's decent, but a bit complicated, and they throttle your queries pretty harshly.
Then I tried MapQuest's, which I found to be surprisingly excellent. I have two apps bound for the app store in the next month or so that use MapQuest's API.
Then I found Geonames, which I'm very impressed by but haven't had the opportunity to use yet. Note that Geonames DOES allow you to download their data, so if you really need network-free service, this might be a solution.
Apart from that, you're going to be calling something off the device. Which, by the way, you are when you use MKReverseGeocoder--that's just a wrapper around Google's reverse geocoding service.