13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

緯度経度の比較

Last updated at Posted at 2012-09-24

self.MyMapView.centerCoordinate.latitudeと newLocation.coordinate.latitudeが同じなのに==でtrueにならない。

typedef struct {
	CLLocationDegrees latitude;
	CLLocationDegrees longitude;
} CLLocationCoordinate2D;

CLLocationDegreesの比較は??

とりあえずdoubleにキャストするかと思ったが、それでもだめで、なんとdoubleとかは==で比較できない驚愕の事実。

fabsつかう。

	double lat1 = (double)self.MyMapView.centerCoordinate.latitude;
	double lon1 = (double)self.MyMapView.centerCoordinate.longitude;

	double lat2 = (double)newLocation.coordinate.latitude;
	double lon2 = (double)newLocation.coordinate.longitude;
	
	if (fabs(lat1 - lat2) < FLT_EPSILON && fabs(lon1 - lon2) < FLT_EPSILON) {
13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?