Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 需要有关MKMapItem的帮助吗_Ios_Mkmapitem - Fatal编程技术网

Ios 需要有关MKMapItem的帮助吗

Ios 需要有关MKMapItem的帮助吗,ios,mkmapitem,Ios,Mkmapitem,我正在使用此代码获取当前位置,并希望使用此信息像whatsapp一样进行共享。在共享位置按钮点击我想发送纬度和经度给其他用户。但它显示出完全不同的位置 CLLocationManager *lm = [[CLLocationManager alloc] init]; lm.delegate = self; lm.desiredAccuracy = kCLLocationAccuracyBest; lm.distanceFilter = kCLDistanceFilterN

我正在使用此代码获取当前位置,并希望使用此信息像whatsapp一样进行共享。在共享位置按钮点击我想发送纬度和经度给其他用户。但它显示出完全不同的位置

CLLocationManager *lm = [[CLLocationManager alloc] init];
    lm.delegate = self;
    lm.desiredAccuracy = kCLLocationAccuracyBest;
    lm.distanceFilter = kCLDistanceFilterNone;
    [lm startUpdatingLocation];

    CLLocation *location = [lm location];

    CLLocationCoordinate2D coord = [location coordinate] ;

    Class mapItemClass = [MKMapItem class];
    if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
    {
        // Create an MKMapItem to pass to the Maps app
        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(coord.longitude, coord.latitude);
        MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
        MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
        [mapItem setName:@"My Place"];
        // Pass the map item to the Maps app
        [mapItem openInMapsWithLaunchOptions:nil];
    }

是否可以像whatsapp一样显示附近的街道或地名以共享。

您可以使用CLLocationManagerDelegate更新位置,并将其存储在全局变量中

将locationManager初始化为

 _locationManager = [[CLLocationManager alloc] init];
     _locationManager.delegate = _locationObjVC;
     locationManager.desiredAccuracy = kCLLocationAccuracyBest;

 [_locationManager startUpdatingLocation]; // start updating it..
//拉手三角门

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
 CLLocation *location = [[CLLocation alloc] initWithLatitude:_userAnnotationPoint.coordinate.latitude longitude:_userAnnotationPoint.coordinate.longitude];
    [_geocoder reverseGeocodeLocation:location completionHandler:
     ^(NSArray *placemarks, NSError *error)
     {
         NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
         if (error){
             NSLog(@"Geocode failed with error: %@", error);
             //[self displayError:error];
             _userAnnotationPoint.subtitle = [NSString stringWithFormat:@"Lati:%f Long:%f",_userAnnotationPoint.coordinate.latitude,_userAnnotationPoint.coordinate.longitude];
         }
         else
         {
             CLPlacemark *placemark = [placemarks objectAtIndex:0];

             NSLog(@"Received placemarks: %@", [NSString stringWithFormat:@"%@",[[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]]);
             //            clickedAnnotationPoint.subtitle = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ %@ %@ %@",
             //            placemark.ISOcountryCode,placemark.country,placemark.postalCode,placemark.administrativeArea,          placemark.subAdministrativeArea,placemark.locality,placemark.subLocality,placemark.thoroughfare,           placemark.subThoroughfare];
             _userAnnotationPoint.subtitle = [NSString stringWithFormat:@"%@",[[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]];
         }

     }];
    }