2011-09-26 155 views
0

我只是想計算兩個位置之間的距離。 在哪個用戶可以輸入位置的地址,並從該地址我想要計算它們之間的距離。使用iphone中的谷歌地圖計算兩個位置之間的距離

是否可以使用這些地址計算CLLocation的距離?

如果您有任何鏈接/代碼,請發送給我。

請儘早幫助我。這很緊急。

在此先感謝。

回答

7

首先,您需要將地址代碼到緯度/經度,然後您可以使用CLLocation框架來計算距離。 要對地址進行地址解析,可以使用forward geocoding API

// get CLLocation fot both addresses 
CLLocation *location = [[CLLocation alloc] initWithLatitude:address.latitude longitude:address.longitude]; 

// calculate distance between them 
CLLocationDistance distance = [firstLocation distanceFromLocation:secondLocation]; 
相關問題