I am developing an instant messaging chat app.In which the user have to enter it's zipcode and when he will go for the search option there is a particular radius in miles given by him through which the search operation will perform.So now I have two zipcode one is user's and another is my friend's zipcode from that how can I get the users within that radius between them and their location.Can you please help me how to proceed and which frameworks i should use to get these.Please help me as I am a newbe in iOS development.
3 Answers
First you need to convert the zip code / address into a lat/long position using CLGeocoder
. Once you have those positions you can:
If you want the actual distance use CLLocation
and distanceFromLocation:
.
If you want the driving distance you need to use a navigation framework to get directions, like MKDirections
.

- 118,658
- 15
- 128
- 151
-
can you please tell me how to or where to get navigation framework? – Sushrita May 08 '15 at 11:59
-
`MKDirections`? Its part of MapKit – Wain May 08 '15 at 12:10
Refer this answer to get Latitude and Longitude from zipcode. Once you get the zipcodes of your source and destination, you can get the distance using this answer.
Please note that it will be air distance and not the actual distance. You can evaluate Google Map or direction API to find actual distance.
There is no direct solution for getting the distance between 2 zipcode but you can use google API for getting the lat long of your zip code and then using those lat long you can find the distance between the zipcodes.
#import <CoreLocation/CoreLocation.h>
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];