如何在 iPhone 地图上显示用户的位置和其他点?
基本上我想在地图上显示用户位置以及所选位置的列表。它甚至可以有标准的 iPhone 注释。但是,我不知道实现这一目标将采取的一般步骤。我会使用 MKMapView 或 Core Location,还是两者都使用?有人可以给我一个简单的步骤概要,或者一个好的教程或示例代码的链接。感谢
扩展,我想知道是否有任何关于如何处理位置数组的示例。我猜测我需要识别用户位置,然后设置我想要参考距用户多远的半径,然后用适合该半径的位置数组填充该半径。我对此的想法正确吗?有没有任何例子可以说明如何至少完成其中的一部分。我见过很多关于如何显示单个位置的示例,但没有一个涉及多个位置。
Basically I want to show the users location plus a list of selected location on a map. It can even have the standard iphone annotations. But, I have no idea of the general steps I would take to achieve this. Would I use MKMapView, or Core Location, or both? Could someone give me a simple outline of steps to take, or a link to a good tutorial or sample code. Thanks
To expand, I was wondering if there are any examples anywhere on how to deal with arrays of locations. I'm guessing that I would need to identify the users location then set up a radius of how far I want to reference locations away from the user, then populate that radius with an array of location that fit within that radius. Are my thoughts on this correct? And are there any examples out there of how to do at least a part of this. I have seen a ton of examples on how to show a single location, but none dealing with multiple locations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我正在使用的东西,可能会对您有所帮助。它将为您提供一个适合 CLLocations 数组的 MKCooperativeRegion。然后,您可以使用该区域将其传递给 MKMapView setRegion:animated:
由于您可能已经建立,因此您需要使用 MKMapView 和核心位置来执行您想要的操作。在我的应用程序中,我知道要显示哪些位置,然后使 MKMapView 足够大以容纳它们。上面的方法将帮助您做到这一点。但是,如果您想获取适合给定地图区域的位置列表,那么您必须或多或少地执行与我上面所做的相反的操作。
Here's something I'm using that may help you. It will give you an MKCoordinateRegion that fits an array of CLLocations. You can then use that region to pass it to MKMapView setRegion:animated:
As you're probably already established, you'll need to use a MKMapView and Core Location to do what you want. In my app I know what locations I want to display, and then make the MKMapView big enough to fit them all in. The method above will help you do that. If however you want to get a list of locations that fit within a given map region, then you'll have to do more or less the reverse of what I'm doing above.
这里有三个:
Here's three: