2016-09-26 81 views
0

所以我一直在做一個獲取用戶位置的任務。
我在這段代碼上工作,它在模擬器上構建並運行良好。
但它沒有得到我當前的位置。
我在找什麼?如果是這樣,請幫助!
這裏是我的代碼:獲取用戶位置

Capture from Xcode

+2

請不要將您的代碼作爲圖像發佈。請將相關代碼複製並粘貼到文本中,並將其放入您的問題中。 – rmaddy

+0

您是否已將隱私通知文本添加到項目的Info.plist中? – dasdom

+0

我很抱歉,由於代碼有點大,我認爲最好以圖片形式發佈。謝謝你的提示! –

回答

0

你可以試着改變你的didUpdateLocation了這一點。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 

     let userLocation:CLLocation = locations[0] as CLLocation 

     locationManager.stopUpdatingLocation() 


     let location = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude) 

     let span = MKCoordinateSpanMake(0.05, 0.05) 

     let region = MKCoordinateRegion(center: location, span: span) 

     myMap.setRegion(region, animated: true) 


    } 

希望它能幫助你。

+2

更好的答案可以解釋OP的代碼有什麼問題,並解釋此代碼如何解決此問題。 – rmaddy