获取 iphone 地图套件位置之间的所有坐标

发布于 2024-10-08 07:47:31 字数 88 浏览 5 评论 0原文

谁能告诉我如何获取位置之间的所有纬度、经度值...??? 作为实现的一部分,我希望拥有起点和终点之间的所有纬度、经度值来绘制路线。

提前致谢...

Can anyone tell me how to get all Lat,Long values between to locations...???
As part of implementation I would like to have all the Lat,Long values between the start end end point to draw the route.

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽清风入怀 2024-10-15 07:47:31

找到这些点非常简单,不需要任何聪明的三角学。请注意,如果点之间的距离需要是特定的距离(例如每 100 米),则需要三角学。不过,我们将制作简单版本。

基本上,您可以计算出纬度之间的差异和经度之间的差异,决定需要多少个点(如上所述,“全部”是一个无限数),将距离除以点数,然后迭代它们。 (注意:我还没有测试过这段代码,但你应该能够明白。)

// Making my own names for your start and stop coordinate, use your own
CLLocationCoordinate2D startPoint; // Your starting latitude and longitude
CLLocationCoordinate2D stopPoint;  // Ending latitude and longitude

CLLocationCoordinate2D newPoint;   // A newly-created point along the line

double latitudeModifier;    // Distance to add/subtract to each latitude point
double longitudeModifier;   // Distance to add/subtract to each longitude point

int numberOfPoints = 100;   // The number of points you want between the two points

// Determine the distance between the lats and divide by numberOfPoints
latitudeModifier = (startPoint.latitude - endPoint.latitude) / numbernumberOfPoints;
// Same with lons
longitudeModifier = (startPoint.longitude - endPoint.longitude) / numbernumberOfPoints;

// Loop through the points
for (int i = 0; i < numberOfPoints; i++) {
    newPoint.latitude = startPoint.latitude + (latitudeModifier * i);
    newPoint.longitude = startPoint.longitude + (longitudeModifier * i);

    // Do something with your newPoint here

}

Finding the points is pretty straightforward and doesn't require any clever trigonometry. Note that if the distance between points needs to be a specific amount -- say every 100 meters -- then trigonometry will be required. We'll do the simple version, though.

Basically you figure out the difference between the latitudes and the difference between the longitudes, decide how many points you want (as noted, "all" is an infinite number), divide the distance by the number of points, and iterate through them. (Note: I haven't tested this code, but you should be able to get the idea.)

// Making my own names for your start and stop coordinate, use your own
CLLocationCoordinate2D startPoint; // Your starting latitude and longitude
CLLocationCoordinate2D stopPoint;  // Ending latitude and longitude

CLLocationCoordinate2D newPoint;   // A newly-created point along the line

double latitudeModifier;    // Distance to add/subtract to each latitude point
double longitudeModifier;   // Distance to add/subtract to each longitude point

int numberOfPoints = 100;   // The number of points you want between the two points

// Determine the distance between the lats and divide by numberOfPoints
latitudeModifier = (startPoint.latitude - endPoint.latitude) / numbernumberOfPoints;
// Same with lons
longitudeModifier = (startPoint.longitude - endPoint.longitude) / numbernumberOfPoints;

// Loop through the points
for (int i = 0; i < numberOfPoints; i++) {
    newPoint.latitude = startPoint.latitude + (latitudeModifier * i);
    newPoint.longitude = startPoint.longitude + (longitudeModifier * i);

    // Do something with your newPoint here

}
巴黎夜雨 2024-10-15 07:47:31

你所说的“全部”是什么意思?由于纬度/经度对是双精度的,因此您正在谈论无限多个点。

如果你想在两点之间画一条线,你可以使用 CAShapeLayer 在地图上画一条线来连接它们。

然而,“路线”一词意味着您想知道沿着道路行驶的点。再说一遍,你真正要求的是什么?人们可以驾驶的路线?走?坐公交车吗? MapKit 本身根本无法帮助您进行路由,您必须查看其他第三方框架。

What do you mean by "all"? Since lat/long pairs are doubles, you are talking about an infinite number of points.

If you want to draw a line between two points you can use a CAShapeLayer to draw a line on the map to connect them.

The word "route" however impies you want to know points that travel along a road. There again, what are you really asking for? Routes people could drive? Walk? Take a bus? MapKit itself does not help you with routing at all, you would have to look at other third party frameworks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文