Mapkit Userlocation Coordinatesを返す
質問
現在の場所の緯度/経度座標を返そうとすると、エラーの説明なしでアプリケーションがクラッシュします...
NSLog(@"%@", mapView.userLocation.location.coordinate);
電話が場所を見つけるまで待っています...
解決
mapView.userLocation.location.coordinate
は構造体ですが、%@
形式指定子はオブジェクトを想定しています。これは動作します:
NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude,
mapView.userLocation.location.coordinate.longitude);
他のヒント
何らかの理由で、これはうまくいきませんでした。座標(0.0000、0.0000)に移動します。あなたがそれをチェックアウトする機会がある場合、以下は私のコードです。助けてくれてありがとう!
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
所属していません StackOverflow