1

こんにちは、私のアプリケーションでは、現在の場所から目的地までのルート マップを表示する必要があります。そのために、google mapURL を使用してルート マップを表示しています。すべて正常に動作します。しかし、問題は、アプリを初めてインストールして現金を取得し、現在の場所を取得していないことです。

アプリケーションを最小化すると、アラートメッセージが表示されます。

"appname" would like to use Your current Location

[OK] をクリックした後、アプリケーションを閉じて再度開き、ルート マップを表示します。

私のコード。

-(void)currentlocation{
     locationManager = [[CLLocationManager alloc]init];

     locationManager.delegate = self;


     locationManager.distanceFilter = kCLDistanceFilterNone;


     locationManager.desiredAccuracy = kCLLocationAccuracyBest;


     [locationManager startUpdatingLocation];


     [self->locationManager startUpdatingLocation];


      CLLocation *location = [locationManager location];


      CLLocationCoordinate2D coordinate = [location coordinate];

      mapView = [[[MapView alloc] initWithFrame:
            CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];

    [self.view addSubview:mapView];

   Place* home = [[[Place alloc] init] autorelease];
    home.name = @"Home";
    home.description = @"Sweet home";
    home.latitude = 13.0051850;
    home.longitude = 77.62698590;

       Place* office = [[[Place alloc] init] autorelease];
    office.name = @"Office";
    office.description = @"Bad office";
    office.latitude = coordinate.latitude;
    office.longitude = coordinate.longitude;

        [mapView showRouteFrom:home to:office];

    }

ユーザーがアプリケーションを開いたときにアラートを表示する必要がある上記のコードを使用しました。ユーザーが[OK]をクリックすると、ルートマップが表示されます。達成する方法を教えてください。私は長い間ここで立ち往生しています助けてください私から。

ありがとう。

4

1 に答える 1

2

このパを試してみてください..

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {

        Place* home = [[[Place alloc] init] autorelease];
        home.name = @"Home";
        home.description = @"Sweet home";
        home.latitude = 13.0051850;
        home.longitude = 77.62698590;

        Place* office = [[[Place alloc] init] autorelease];
        office.name = @"Office";
        office.description = @"Bad office";
        office.latitude = currentLocation.coordinate.latitude;
        office.longitude = currentLocation.coordinate.longitude;
        [mapView showRouteFrom:home to:office];


    }
    // Stop Location Manager
    [locationManager stopUpdatingLocation];
}
于 2014-06-17T06:20:33.397 に答える