How to know distance between places - iphone

Hello I am creating travel app. I want to find current location and find the distance between selected hotel or place from this location.. I searched core location but it is not returning longitude and latitude of current location in simulator .please help me and how can I calculate distance ?

To calculate distances you can use the distanceFromLocation: method of the CLLocation class.

Related

plot pins on MKMapView around 10 kms from current location

I have an MKMapView & I am using PinAnnotation for plotting the pins on MKMapView.
I have a local database which contains the latitude & longitude of thousands of locations. I want to plot the pins around 10 kms from current location on MKMapView, when the application is launched.
It depends what your database. A simplistic way would be to work out the longitude difference for 10km (it is different at the equator and near the north pole) and the latitude difference for 10km, then search your database for everything between maxLat and minLat and maxLong and minLong. That gives you items in a rectangle but it's a start. From there you could cycle through every result, make it a CLLocation and check it is within 10km using distanceFromLocation.
I done it using the following way -
1) First found the current latitude & longitude using the delegate method of MKMapView(didUpdateUserLocation).
2) Found the distance from the current location with the location stored in my local DB in KM.
3) If distance <=10 Kms, then plot pin, else do nothing.

How to calculate distance to locations

I've developed an iPhone application to parse data from an XML file. This data contains a set of longitudes and latitudes for different places.
How do I detect nearest of them according to my current location on the map and how do I set set a range to show places in this range?
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:myLatitude longitude:myLongitude];
CLLocation *myXmlLocation = [[CLLocation alloc] initWithLatitude:xmlLatitude longitude:xmlLongitude];
CLLocationDistance distance = [myLocation distanceFromLocation: myXmlLocation];
This is in meters, so you must do any converting from there. They are also linear, so these aren't driving direction lengths by any means. Good luck.
some trig, but really not too difficult.
this page has an example script, not in your language, but it contains explainations and the equations you need.
http://www.movable-type.co.uk/scripts/latlong.html
and also, please don't write run-on sentences, it took me a while to read your question.
#Vinnie said is absolutely right but these values is air distance.
Also this method is deprecated in iOS 3.2
- (CLLocationDistance)getDistanceFrom:(const CLLocation *)location Parameters
You can't find the distance based on roads with the Apple SDK. Try to use google APIs for finding distance between two points on earth on roads.

IOS Core location - Find out nearest branch

I have create a program to find out my current location using IOS corelocation framework.It works fine.
I need to create a program that list nearest branchaes of a shop chain, while a user travel with the phone.My data base contains the branches details with Latitude and lognitude.How i compare with these details to find out the nearest branch.
Help is highly appreciated.Anybody knows any example program
Thanks,
VKS
You can make use of distanceFromLocation: method of CLLocation.
distanceFromLocation:
Returns the distance (in meters) from the receiver’s location to the
specified location.
(CLLocationDistance)distanceFromLocation:(const CLLocation
*)location
Parameters
location
The other location.
Return Value
The distance (in meters) between the two locations.
Discussion
This method measures the distance between the two locations by tracing
a line between them that follows the curvature of the Earth. The
resulting arc is a smooth curve and does not take into account
specific altitude changes between the two locations.
Availability
Available in iOS 3.2 and later.
By using this method to get the distances of the shops with your current location, you can then sort the list based on the distance to get the nearest branch
VKS, I got to solve the exact same problem too now (using apptarget iOS 5). Do you have any example code / snippets / tips to share for this problem, that I assumed you solved a long time ago? The above is very good explanation from 7KV7, but some examples will speed up my process a lot. Thank's :-)

how can i get distance bettween two place?

hello i want distance between two place ... means i have two places latitude and longitude then i want distance between that two place
i want something like this...
http://maps.google.com/maps?saddr=23.029772,72.527871&daddr=23.1901748,72.0127743
not like php or .net or java function that give calculate distance ...
if i search result by function it give me 55.61 output for this latitude and logitude and in map it give me 65.5 output. how can i get this in json ot xml or any other formate ?
...there's an in-built function in iOS that will do this for you. Check out the CLLocation documentation. Particularly distanceFromLocation:, which as the name suggests returns the difference between two locations in meters. You can create a CLLocation object using lat and lon.
If you don't want a straight line distance, you need to use the Google Directions API, which is well documented here: http://code.google.com/apis/maps/documentation/directions/

Calculate distance from Location - iPhone

I'm trying to calculate the distance between two places user Core Location. I've found a few posts that state to use
-(CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Found some other test code in the thread below:
CLLocationDistance NaN
I'm not sure how to put it all together, to get the result I want ?
Anyone any thoughts ?
Regards,
Stephen
If you have a location named myLocation and want to find the distance from another location, say, restaurantLocation, then it seems you would do something like
CLLocationDistance distance = [myLocation distanceFromLocation:restaurantLocation]
This will give you the distance, in meters, between the two.