Returning Mapkit Userlocation Coordinates

 ̄綄美尐妖づ 提交于 2019-12-13 00:27:14

问题


whenever I try to return the lat/long coordinates for my current location, my application crashes with no explanation of the error...

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

I am waiting until the phone finds the location as well...


回答1:


mapView.userLocation.location.coordinate is a struct while the %@ format specifier expects an object. This will work:

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



回答2:


For some reason, this didn't work for me. It's taking me to the coordinates (0.0000, 0.0000). Below is my code if you have a chance to check it out. Thanks for the help!

[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];


来源:https://stackoverflow.com/questions/1652289/returning-mapkit-userlocation-coordinates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!