こんにちは私はマップビューの基本アプリケーションを開発しています。私はマップビューですべてをほぼ完了しましたが、2つの異なるマップビューリージョンを比較したり、マップビューの新しいエリアを見つけることができませんでした。たとえば、ユーザーが地図をドラッグすると、地域がどれだけ変化したかを知りたいと思います。2つの異なるマップビュー領域を比較してその違いを見つける方法
0
A
答えて
-1
この回答は2つのマップポイントを比較する方法を示しています。あなたは地図の地域の中心にこれを使うことができます:link。
0
最初に地図の初期領域を見つける必要があります。 ...あなたが最初に(あなたのviewDidLoad中)でこれを見つけることができ、あなたのマップがMapViewの命名されたと言う:
CLLocationCoordinate2D center = mapView.centerCoordinate;
CLLocationDegrees lat = center.latitude;
CLLocationDegrees lon = center.longitude;
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span = region.span;
//Assuming they have been declared as instance variables of type double
current_lat_low = lat - span.latitudeDelta/2.0;
current_lat_high = lat + span.latitudeDelta/2.0;
current_lon_low = lon - span.longitudeDelta/2.0;
current_lon_high = lon + span.longitudeDelta/2.0;
これはあなたに示すマップの初期面積を与えます。次に、
- (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;
}
再申請ありがとうございます。 – Nit
これは2点間の距離ではなく2点間の距離を比較する質問に対する答えではありません。 –