How to find direction between two location in iPhone application?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 23:47:34

You can use different methods for finding the direction between two location.

(1) Using Google Maps

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLatitude, currentLongitude, destinationLatitude, destinationLongitude];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

(2) Using Apple Maps:

NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%f,%f&daddr=%f,%f", currentLatitude, currentLongitude, destinationLatitude, destinationLongitude];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

Please let me know if you need any help.

your question is not very clear, but i think you mean the bearing between two locations. see this question: Calculating bearing between two CLLocationCoordinate2Ds

If your points are close together just use trigonometry. That will be close enough. If they are farther away then you want a great circle course, use the Haversine formula.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!