如何使用 MKMapView 显示从当前位置到最近地点的路线
我刚开始在 iPhone 上使用 MapKit。
在 Google 地图上,我有当前位置和图钉来指示当前位置周围最近的位置。 (所有的坐标都是硬编码的,就像现在一样)。
现在,如何执行以下操作: 1. 显示一个绿色箭头(右/左箭头),指向距当前位置最近的图钉位置? 2. 如何播放“右转 1 英里”等语音以到达距当前位置最近的位置?
I am new to using MapKit on iPhone.
On Google Maps, I have a current location and push pins to indicate nearest places around current location. (The co-ordinates of all are hard-coded as on now).
Now, How to do the following:
1. Display a green arrow (right/left arrow) pointing to the nearest push pin location from current location?
2. How to play a voice saying "Take right for 1 mile" etc to reach nearest location from current location?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有明确的解决方案,但一些想法可能对您有帮助。
您可能可以使用自定义 MKAnnotationView,其图像将是绿色箭头。然后,您可以将此注释(箭头)放置在当前位置的顶部。然后您可以找到最近的图钉(通过检查其到当前位置的距离)并找到图钉与当前位置之间的角度。通过该角度,您可以旋转箭头图像,使其指向最近的图钉。
您可以获得用户的当前位置和航向,并且可以获得从当前位置到最近的图钉的距离。通过这些信息,您可以计算出用户需要行驶多远以及朝哪个方向行驶。我不确定你是否想要合成声音或者你是否准备好音频文件。您可能需要连续播放短片(例如“take”+“right”+“for”+“1”+“mile”)。看看 Apple 音频节目指南。据我所知,您无法在当前的地图套件中获得特定于街道的方向(例如,在主街道上右转)。
祝你好运。
I don't have a definite solution but some ideas which might help you.
You can probably use a custom MKAnnotationView whose image will be the green arrow. You can then place this annotation (arrow) on top of your current location. Then you can find the closest pin (by checking its distance to the current location) and find the angle between the pin and the current location. With that angle you can rotate your arrow image so that it points towards the nearest pin.
You can get the user's current location and heading and you can get the distance from the current location to the nearest pin. With this information you can figure out how far and in what direction the user needs to travel. I'm not sure if you want to synthesize the voice or if you have audio files ready. You'll probably have to play back short clips back to back (eg "take" + "right" + "for" + "1" + "mile"). Have a look at Apple's audio programming guide. As far as I know, you can't get street-specific directions in the current mapkit (eg. turn right on Main street).
Good luck.