Skip to content

Instantly share code, notes, and snippets.

@nantekkotai
Created March 29, 2012 06:23
Show Gist options
  • Select an option

  • Save nantekkotai/2234119 to your computer and use it in GitHub Desktop.

Select an option

Save nantekkotai/2234119 to your computer and use it in GitHub Desktop.
MapKitでなぜかうまくいかないパターン

viewDidLoad内にて

// 以下の方法で初期緯度経度と範囲を指定して
MKCoordinateRegion region = myMapView.region;
region.center.latitude = 139.759955;
region.center.longitude = 35.674799;
region.span.latitudeDelta = 0.005;
region.span.longitudeDelta = 0.005;

// これを実行するとなぜか
[myMapView setRegion:region animated:YES];

こんなログが出る

2012-03-29 15:18:18.013 mapkit[3045:11603] *** Terminating app due to uncaught exception   'NSInvalidArgumentException', reason: 'Invalid Region <center:+139.75995500, +35.67479900 span:+0.00500000, +0.00500000>'

以下の書き方では正しく動いた

CLLocationCoordinate2D coordinate;
coordinate.latitude = 35.674799;
coordinate.longitude = 139.759955;

MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
MKCoordinateRegion region_ = MKCoordinateRegionMake(coordinate, span);
[myMapView setRegion:region_ animated:YES];

最初のパターンは本に載っている例なのに動かない。
何か根本的に間違っているかもしれない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment