gpt4 book ai didi

iphone - 有可能知道 CLLocation 点是否在 MKCoordinateRegion 中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:45:01 25 4
gpt4 key购买 nike

我有一个 CLLocation 点(纬度/经度),我想知道它是否在确定的 MKCoordinateRegion 中。我想知道哪个区域是以前制作的 CLLocation 点。

谢谢。

我找到了解决方案。

MKCoordinateRegion region = self.mapView.region;

CLLocationCoordinate2D location = user.gpsposition.coordinate;
CLLocationCoordinate2D center = region.center;
CLLocationCoordinate2D northWestCorner, southEastCorner;

northWestCorner.latitude = center.latitude - (region.span.latitudeDelta / 2.0);
northWestCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
southEastCorner.latitude = center.latitude + (region.span.latitudeDelta / 2.0);
southEastCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);

if (
location.latitude >= northWestCorner.latitude &&
location.latitude <= southEastCorner.latitude &&

location.longitude >= northWestCorner.longitude &&
location.longitude <= southEastCorner.longitude
)
{
// User location (location) in the region - OK :-)
NSLog(@"Center (%f, %f) span (%f, %f) user: (%f, %f)| IN!", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta, location.latitude, location.longitude);

}else {

// User location (location) out of the region - NOT ok :-(
NSLog(@"Center (%f, %f) span (%f, %f) user: (%f, %f)| OUT!", region.center.latitude, region.center.longitude, region.span.latitudeDelta, region.span.longitudeDelta, location.latitude, location.longitude);
}

最佳答案

关于iphone - 有可能知道 CLLocation 点是否在 MKCoordinateRegion 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14916830/

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