find nearest places in iPhone - iphone

Hello all iPhone developers,
I am developing an iPhone application.
In this application i want to find nearest places related to current CLLocation that I am getting from the iPhone device.
I have currently a database in different server .
I am accessing it via .NET web service.
In the database for testing purpose i have created some records with fields of latitude and longitude that I have taken from google maps.
Now ,My Question is that:
How can I determine that the location in the database is near by( within a range of kelometers) the current location ?
I have my options as below:
if
i have to get a address based and currentLocation.latitude and
currentLocation.longitude and pass it
to the service where i compare it
with the available address ( i have
read somewhere "geocoding").
else if
i can pass the latitude and longitude directly to the web-service
and do (what type of i want some
suggestion if any one knows) some
calculations there and give back the
nearest places data back to iPhone.
else
or this solution is completely
logical and if anyone have solution
reagrding it or a tutorial then it
will be useful.

It's true, there are a lot of reverse geocoding services out there (Google, Yahoo!, GeoNames, etc.) to convert from a lat/lon pair to a street address.
But if you have lat/lon pairs in your database already, then I don't think you ever need to convert to a street address. Calculating distances is much easier if all your points are represented by lat/lon, you can use the Haversine formula.
And in fact, if your database natively supports spatial types (for example, MS SQL 2008 appears to), then you can push that calculation into the database layer and not have to worry about it. That seems like the right approach to me: have your iPhone app send lat/lon to your web service and have the database calculate the nearest points-of-interest.

Related

Store locator for iOS using Google Maps

I am looking to add a "store locator" to a simple iOS application.
The ideal situation is the following...
A user will enter their zip code.
The map will display the store locations within a radius of that zip code
The locations will be stored a Google Places account (if easier, I don't mind if the locations are stored within the app code.)
Results can be displayed on a map or list view, or both. (no preference)
Does anyone know how to do this? Or of a tutorial that I can follow?
Ive searched around for a while and I cannot find a decent tutorial to get this done.
Thanks!
Here's how I would approach this:
1) Download your list of stores.
2) Ask them for the postal code/address and then geocode that to retrieve the longitude and latitude coordinates.
3) Display the long/lat on the map, as well as your stores. They can then see what is nearest to them.
4) Since you have the stores downloaded, preferably with a long/lat for each store, you can then calculate the distance away to the store and order them in an ascending fashion in the list, thus showing the closest ones first.

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.

Get zip code from latitude, longitude?

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

Displaying nearby businesses in mapkit

Is it possible to display nearby businesses in mapkit? If not, how else can that be done?
Is there a way to display by category - restaurant, retail, museums?
Also, I don't think displaying traffic flow is available. Can anyone confirm?
The current version of MapKit does not support such features.
It's main capabilities currently are:
a scrollable/zoomable map
reverse geocoding (get the address for some given lat/long coordinates)
add annotations (pins) at a given lat/long
show phone's current location
show Standard, Satellite, or Hybrid view
To display nearby businesses, you would have to:
query a third-party for that information which would ideally return lat/long coordinates
add annotations to the map using the returned coordinates
This is an interesting and emerging business idea!
I live in Nordic region and there is an open Mashups especially for sweden.
By open i mean, any one can request and get access to the content to find nearby Cafe / WiFi / Sushi restaurants etc..
BEGIN PLUG WARNING
Check my iphone application which fetches content from the mashups and display using MapKit!
END PLUG WARNING
And there is a commercial content provider called Info24 for nordic countries at the moment.
Like DyingCactus said, it's not currently possible without using your own calls to one of the mapping service providers. There are options available, though.
One of them is CloudMade. They have a good iPhone library and support almost all of your requirements.
Check out the API at Cloudmade.com
I know this thread is kind of old, but i figured out a free alternative to do what you are looking for, more or less. You just nee to tap into a maps.google.com service and get a kml or JSON output. I used KML (XML) becuase i found the filesize to be consistently smaller. I wrote a 3 part series on my blog about how to do this for anyone that is interested.
http://www.zen-sign.com/finding-business-listings-and-displaying-with-mapkit-part-1/
http://www.zen-sign.com/finding-business-listings-and-displaying-with-mapkit-part-2/
http://www.zen-sign.com/finding-business-listings-and-displaying-with-mapkit-part-3/

Location Based Application for iphone

I want to create an application which retrieves the latitude and longitude value of the current position of the iphone, give those values to some 3rd party server and gets details about that place, if possible show a map of that area on an imageview. I've done for the part of getting the locale information, ie to get the latitude and longitude value. I don't know about the providers those who are serving for the latter part. If anyone knows about this, pls help.
You can use the CLLocationManager class to retrieve longitude and latitude, then use a MKMapView to render it.
If I understand correctly you have the long and lat of the phone from CoreLocation and you want a server to retrieve some information from based on that location.
It's a bit of a broad question but here goes: If you want to build your own geo server, you should look at SimpleGeo. If you want to build something more complex, you are going to have to start building your own server. I would suggest Django-geo or if you have really specialised needs, the PostGIS extensions for Postgres as your foundation.
If you just want to build a simple test app, the Twitter geo apis are a good test bed.
In case you're working with the 3.0 SDK, this page may help you on your way.