你是對的! 要獲取設備使用GPS硬件的經度和緯度信息。 這是沒有互聯網連接。你需要的是一個GPS信號!但是,如果您在建築物內通常沒有良好的GPS信號,則iPhone會嘗試使用周圍的3G和WIFI網絡定位設備。
如果你想顯示那個座標例如谷歌地圖你需要互聯網連接來加載地圖根據你得到的座標。此外,爲了檢索地址,街道等信息,設備需要訪問互聯網以搜索數據庫中的這種信息。
例爲iOS:
拳進口#import<CoreLocation/CoreLocation.h>
到您的.h文件。
然後基本上你需要CLLocationManager
。
- (IBAction)startSearchingLocation:(id)sender
{
//locationManager is ivar of CLLocationManager
self.locationManager = [[CLLocationManager alloc] init];
//release it when you stop the location manager!
// make self the delegate of the location manager
[locationManager setDelegate:self];
//Note that this settings will have a huge impact on battery life!
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//And finally start the location manager.
[locationManager startUpdatingLocation];
}
外景經理將開始發送位置信息到被稱爲委託方法 :
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
我們推薦拋出的第一個結果了,因爲他們可能是舊的緩存數據。同時檢查準確性,確保你在這裏獲得好的結果。
參考:
欲瞭解更多信息請查看this和this文檔。
另請參閱蘋果示例代碼Locations
。
您應該記住iOS(和大多數Android手機)使用A-GPS(輔助GPS),實際上它需要網絡連接。沒有網絡連接,可能需要一些時間以合理的準確度返回一個位置。 – lxt
嗯..如果我的應用需要時間來收集位置數據 - 這可能會關閉我的用戶。我有興趣知道有多少時差,如果我們可以發送到後臺工作或沒有? –