2016-09-26 65 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