1

私はこのコードを使用して現在の場所を取得し、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のように、近くの通りや場所の名前を表示して共有することは可能ですか。

4

1 に答える 1

0

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:@", "]];
         }

     }];
    }
于 2013-01-07T06:41:27.323 に答える