如何在MKMapView上显示当前位置 [英] how to show current location on MKMapView

查看:252
本文介绍了如何在MKMapView上显示当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序上使用MKMapView。我需要在模拟器上显示当前位置。

是否有可能。在模拟器上显示当前位置。

I am using MKMapView on my application. i need to show current location on simulator.
is it possible. to show current location on simulator.

推荐答案

在模拟器中,用户的当前位置始终位于加州库比蒂诺。

In the simulator, the user's current location is always in Cupertino, California.

如果您使用Interface Builder添加地图视图,只需选中属性检查器中的显示用户位置复选框以获取地图视图。 (选择地图视图并键入 command-1 以显示属性检查器。)

If you're using Interface Builder to add your map view, simply check the "Shows User Location" check box in the Attributes Inspector for the map view. (Select the map view and type command-1 to display the attributes inspector.)

如果您要添加或以编程方式操作地图视图,设置 showsUserLocation 地图视图属性为 YES

If you're adding or manipulating the map view programmatically, set the showsUserLocation property of the map view to YES.

更新:事实证明这是可能的,只是没有使用内置的地图视图功能,并不总是有效。

Update: It turns out that this is possible, just not using the built in map view functionality, and it doesn't always work.

最新版本的SDK(必须在Snow Leopard上运行)可以使用CLLocationManager获取模拟器运行的机器的位置。然后,您可以使用此位置创建要在地图视图上显示的注释。它不会像内置的用户位置指示器(至少没有一些工作),但它会显示用户的当前位置。

Recent versions of the SDK (which have to run on Snow Leopard) can get the location of the machine the simulator is running on using CLLocationManager. You can then use this location to create an annotation to display on the map view. It won't behave like the built in "user's location indicator" (at least not without some work), but it will show the user's current location.

参见这篇文章了解这项技术什么时候不起作用的细节。

See this post for details of when this technique won't work.

请参阅 CLLocationManager文档,用于使用CLLocationManager和CLLocationManagerDelegate的示例代码,然后在地图视图中显示用户的位置。

See the "Related sample code" section of the CLLocationManager documentation for sample code that uses CLLocationManager and CLLocationManagerDelegate and then displays the user's location on a map view.

这篇关于如何在MKMapView上显示当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆