在地图加载之前查找用户位置
我正在尝试使用以下方法查找用户的位置:
CLLocationCoordinate2D _location;
CLLocation *userLoc = nil;
if(appDelegate.clLocationManager.locationServicesEnabled){
userLoc = mapView.userLocation.location;
_location = userLoc.coordinate;
}
问题是我尚未初始化地图,因此上述方法不起作用。有没有一种方法可以在不使用mapkit的情况下获取用户的位置?或者我应该使用不同的技术?
I'm trying to find the user's location using:
CLLocationCoordinate2D _location;
CLLocation *userLoc = nil;
if(appDelegate.clLocationManager.locationServicesEnabled){
userLoc = mapView.userLocation.location;
_location = userLoc.coordinate;
}
The problem is that I haven't yet initialized the map so the above doesn't work. Is there a way to get the user's location without using mapkit? Or should I be using a different technique?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取用户的位置,您需要在尝试读取位置信息之前实际“启动”位置管理器。我建议您查看 Apple 的 LocateMe 示例。
LocateMe 示例代码
简而言之,获取用户的位置信息可以分两步完成:
...然后,
希望这有帮助!
To get the user's location you need to actually "start" the location manager before trying to read the Location information. I suggest that you look at LocateMe sample from Apple.
LocateMe Sample Code
In a nutshell, getting user's location information can be done in two steps:
... and then,
Hope this helps!
我几乎删除了这个问题,但看到有人投了赞成票。这似乎就是答案:
appDelegate 只是对应用程序委托的引用,我的位置管理器实例位于其中。
I almost deleted this question but see somebody gave it an up vote. This seems to be the answer:
appDelegate is just a reference to the application delegate, where my location manager instance lives.