Iphone 如何比较两个不同的地图视图区域并找出它们之间的差异
大家好,我正在开发地图视图基础应用程序。我几乎用map view做了所有的事情,但我无法比较两个不同的map view区域并找到新的map view区域。例如,如果用户拖动地图,我想找出该区域的变化程度。首先需要找到初始地图区域。假设您的地图名为mapView…您可以首先通过(在viewDidLoad中)找到它: 这将为您显示地图的初始区域。然后在Iphone 如何比较两个不同的地图视图区域并找出它们之间的差异,iphone,xcode,mkmapview,region,Iphone,Xcode,Mkmapview,Region,大家好,我正在开发地图视图基础应用程序。我几乎用map view做了所有的事情,但我无法比较两个不同的map view区域并找到新的map view区域。例如,如果用户拖动地图,我想找出该区域的变化程度。首先需要找到初始地图区域。假设您的地图名为mapView…您可以首先通过(在viewDidLoad中)找到它: 这将为您显示地图的初始区域。然后在 - (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)animated
{
CLLocationCoordinate2D center = mapView.centerCoordinate;
CLLocationDegrees lat = center.latitude;
CLLocationDegrees lon = center.longitude;
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span = region.span;
double lat_low = lat - span.latitudeDelta / 2.0;
double lat_high = lat + span.latitudeDelta / 2.0;
double lon_low = lon - span.longitudeDelta / 2.0;
double lon_high = lon + span.longitudeDelta / 2.0;
//do any work comparing the initial lat/lons with the new values
.....
//set current lat/lon to be the new lat/lon after work is complete
current_lat_low = lat_low;
current_lat_high = lat_high;
current_lon_low = lon_low;
current_lon_high = lon_high;
}
首先,您需要找到初始贴图区域。假设您的地图名为mapView…您可以首先通过(在viewDidLoad中)找到它: 这将为您显示地图的初始区域。然后在
- (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)animated
{
CLLocationCoordinate2D center = mapView.centerCoordinate;
CLLocationDegrees lat = center.latitude;
CLLocationDegrees lon = center.longitude;
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span = region.span;
double lat_low = lat - span.latitudeDelta / 2.0;
double lat_high = lat + span.latitudeDelta / 2.0;
double lon_low = lon - span.longitudeDelta / 2.0;
double lon_high = lon + span.longitudeDelta / 2.0;
//do any work comparing the initial lat/lons with the new values
.....
//set current lat/lon to be the new lat/lon after work is complete
current_lat_low = lat_low;
current_lat_high = lat_high;
current_lon_low = lon_low;
current_lon_high = lon_high;
}
这个答案告诉你如何比较两个地图点。您可以在地图区域的中心使用此选项: 这个答案向您展示了如何比较两个地图点。您可以在地图区域的中心使用此选项: 部分答案。MKCoordinateRegion的均衡遵从性
extension MKCoordinateRegion: Equatable
{
public static func == (lhs: MKCoordinateRegion, rhs: MKCoordinateRegion) -> Bool
{
if lhs.center.latitude != rhs.center.latitude || lhs.center.longitude != rhs.center.longitude
{
return false
}
if lhs.span.latitudeDelta != rhs.span.latitudeDelta || lhs.span.longitudeDelta != rhs.span.longitudeDelta
{
return false
}
return true
}
}
部分答案。MKCoordinateRegion的均衡遵从性
extension MKCoordinateRegion: Equatable
{
public static func == (lhs: MKCoordinateRegion, rhs: MKCoordinateRegion) -> Bool
{
if lhs.center.latitude != rhs.center.latitude || lhs.center.longitude != rhs.center.longitude
{
return false
}
if lhs.span.latitudeDelta != rhs.span.latitudeDelta || lhs.span.longitudeDelta != rhs.span.longitudeDelta
{
return false
}
return true
}
}
我想这真的取决于你想做什么。例如,您可以尝试比较两个区域中心之间的差异。然而,你提到了这个地区
MKCoordinateRegion
只是一个矩形,除非缩放级别发生变化,否则其总面积将相同()。我会给你们指出一个CLCircularRegion,它的面积可以用它的半径来计算,半径和中心是一个暴露的属性
有多种方法可以从地图数据中获取圆形区域。你的问题没有明确说明你是否对区域中心之间的距离感兴趣,但在发现这种差异时,应该有很多答案
如果其中一个场景不是您想要实现的,请给我留言
()我想这取决于你想做什么。例如,您可以尝试比较两个区域中心之间的差异。然而,你提到了这个地区
MKCoordinateRegion
只是一个矩形,除非缩放级别发生变化,否则其总面积将相同()。我会给你们指出一个CLCircularRegion,它的面积可以用它的半径来计算,半径和中心是一个暴露的属性
有多种方法可以从地图数据中获取圆形区域。你的问题没有明确说明你是否对区域中心之间的距离感兴趣,但在发现这种差异时,应该有很多答案
如果其中一个场景不是您想要实现的,请给我留言
()这不是问题的答案,而是比较两点之间的距离,而不是两个区域。这不是问题的答案,而是比较两点之间的距离,而不是两个区域。标题引用在两个区域之间存在差异,而问题涉及寻找新的地图视图区域。有点困惑。目标不明确。两个区域之间的标题参考不一致,而问题是寻找地图视图的新区域。有点困惑。目标不明。