gpt4 book ai didi

iphone - iPhone 应用程序中的 map 集成

转载 作者:行者123 更新时间:2023-12-03 21:11:57 25 4
gpt4 key购买 nike

我想在iPhone中使用 map 套件集成 map ,并且我成功了,但现在我面临的问题是

我有 2 个位置坐标,位置 1 和位置 2,现在我希望这两个点显示在 map 上,但我希望它们同时出现在屏幕上,这意味着如果它们很远,则缩放级别会变为那个点并在 map 上显示这两个点,如果它们彼此靠近,则缩放级别显示从该角度(我的意思是非常接近)。

现在我知道使用经度增量和纬度增量我可以解决这个问题,但我找不到一种方法使其动态,这样我就不必对增量值进行硬编码

任何帮助表示赞赏。谢谢

最佳答案

CLLocationCoordinate2D centerCoordinate;
centerCoordinate.latitude = (location1.latitude + location2.latitude) / 2;
centerCoordinate.longitude = (location1.longitude + location2.longitude) / 2;

MKCoordinateSpan span;
span.latitudeDelta = ABS(location1.latitude - location2.latitude);
span.longitudeDelta = ABS(location1.longitude - location2.longitude);

[mapView setRegion:[mapView regionThatFits:MKCoordinateRegionMake(centerCoordinate, span)]
animated:YES];

关于iphone - iPhone 应用程序中的 map 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2583113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com