MapKit giving wrong lat & lang - iOS 8

前端 未结 4 1466
星月不相逢
星月不相逢 2021-01-25 22:15

When I try to use map in iOS 8, I get below error.

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationMa         


        
4条回答
  •  爱一瞬间的悲伤
    2021-01-25 22:40

    You need to implement the CLLocationManager Delegate ( -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations ) to get location updates.

    Here's a code snippet for your reference:

    -(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
         CLLocation *currentLocation = [locations lastObject];
    
         NSLog(@"ffffff===%f===%f", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
    }
    

    Alternatively, you can implement the Mapkit's following delegate method:

    - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
    {
        MKUserLocation *myLocation = userLocation;
        NSLog(@"ffffff===%f===%f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);
    }
    

提交回复
热议问题