作者tas72732002 (蔥頭)
看板PHP
標題[請益] 取得手機定位後的機緯度問題~~
時間Fri Mar 19 21:21:12 2010
請問一下 如iphone有提供定位功能 是否可透過javascript等程式取得
iphone的經緯度~~ 我在網路上有看到 不過它使用的好像是iphone framework
語言,如下:
我們可以透過CLLocationManager類別取得使用者座標位置。
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
步驟說明:
Step(1):首先,先建立一個CLLocationManager類別的物件。
Step(2):接著指定委派的對象,這裡是指定自己(self)。
Step(3):最後呼叫CLLocationManager類別的一個方法「startUpdatingLocation」,這個時候如果使用者是第一次使用你的iPhone軟體,iPhone就會詢問使用者是否允許iPhone軟體取得使用者座標。
Step(4):當你點選確定後,iPhone就會開始定位,定位完成後就會觸發「didUpdateToLocation」事件。
因此,當定位完成你可以用以下方法取得使用者座標後,接著進行一些處理。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSString *userLat = [[NSNumber numberWithDouble:newLocation.coordinate.latitude] stringValue];
NSString *userLng = [[NSNumber numberWithDouble:newLocation.coordinate.longitude] stringValue];
}
如果是PHP網頁 不知道要如何來取得userLat and userLng???
--
感謝大家的推文
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.167.205.64
→ olctw:原則上 HTML5 有,但是好像還在吵,可以先用 google gear 03/19 21:40
→ olctw:gear 會需要使用者裝額外軟體,即使使用者沒有 GPS 裝置, 03/19 21:41
→ olctw:gear 也會用 IP 去猜使用者位置 03/19 21:42
推 ckaha:GPS定位的資料 原則上應該是需要用到iphone SDK抓出來吧? 03/19 22:27
→ ckaha:不過要用上述的 你要先學會使用objective-C 和有一台mac 03/19 22:28
→ ckaha:不然用迷版也可以 03/19 22:28
→ ckaha:因為iphone開發相關的東西都要$ .... 03/19 22:30
→ ckaha:不然你可以先用不用錢的android (如果不是被限制在iphone上) 03/19 22:31
推 dreambird:W3C Geolocation API 03/20 00:11
→ dreambird:你先搞清楚你要開發web app還是native app吧 03/20 00:13
→ dreambird:Geolocation API safari不支援不過mobile safari有 03/20 00:14
→ dreambird:要測試的話就用firefox 03/20 00:15