返回Mapkit Userlocation坐标

时间:2009-10-30 20:58:10

标签: iphone mapkit

每当我尝试返回当前位置的纬度/经度坐标时,我的应用程序崩溃而没有解释错误......

NSLog(@"%@", mapView.userLocation.location.coordinate);

我在等电话找到位置......

2 个答案:

答案 0 :(得分:5)

mapView.userLocation.location.coordinate是一个结构,而%@格式说明符需要一个对象。这将有效:

NSLog(@"%f, %f", mapView.userLocation.location.coordinate.latitude,
                 mapView.userLocation.location.coordinate.longitude);

答案 1 :(得分:0)

出于某种原因,这对我没有用。它带我到坐标(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];