Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate distance between two place using latitude-longitude in gmap for iPhone [duplicate]

Tags:

ios

iphone

gps

Possible Duplicate:
GPS coordinates in degrees to calculate distances

How to Calculate distance between two place using latitude-longitude in gmap for iPhone? Calculate distance between two place using latitude-longitude in gmap for iPhone

like image 660
Durga Avatar asked Aug 24 '11 12:08

Durga


People also ask

How do you find the distance between two locations using latitude and longitude?

from math import cos, asin, sqrt, pi def distance(lat1, lon1, lat2, lon2): p = pi/180 a = 0.5 - cos((lat2-lat1)*p)/2 + cos(lat1*p) * cos(lat2*p) * (1-cos((lon2-lon1)*p))/2 return 12742 * asin(sqrt(a)) #2*R*asin...

How do you pull up latitude and longitude on iPhone?

Get GPS Coordinates in Maps on iPhone and iPadTap the current location button on the top right. When the blue circle for your spot appears on the map, tap it. Swipe up from the bottom to view full details for your location and you'll see the Latitude and Longitude.


2 Answers

You have to use Core Location Framework. So don't forget to Add & import Core Location Framework.

Objective-C

 #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];   //distance in Meters   //1 meter == 100 centimeter   //1 meter == 3.280 feet   //1 square meter == 10.76 square feet    [locA release];   [locB release]; 

Swift

import CoreLocation  let locA = CLLocation(latitude: lat1, longitude: long1)  let locB = CLLocation(latitude: lat2, longitude: long2)  let distance = locA.distance(from: locB) 
like image 124
Vijay-Apple-Dev.blogspot.com Avatar answered Sep 17 '22 18:09

Vijay-Apple-Dev.blogspot.com


if you have the location parameter, create 2 CLLocations and use [location1 distanceFromLocation:location2] method.

like image 45
Nithin Avatar answered Sep 19 '22 18:09

Nithin