2011-03-16 6 views
0

나는 그가있는 곳에있는 사용자의 현재 위치를 얻고지도에 표시하고 싶습니다. 사용자가 현재 위치에서 목적지 위치에 도달하면 위치 목적지 위치는 여행 방향을 따라지도에 표시되어야합니다. 행동의 라인 1아이폰의지도에서 현재 위치의 위치를 ​​얻는 방법

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation{ 
    [manager stopUpdatingLocation]; 
    printf("\n Latitude = " "\n Longitude = " " ",[NSString stringWithFormat:@"%.7f",newLocation.coordinate.latitude],[NSString stringWithFormat:@"%.7f",newLocation.coordinate.longitude]); 
} 



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    CLLocationManager *locationManager = [[[CLLocationManager alloc]init]autorelease]; 
    locationManager.delegate = self; 
    [locationManager startUpdatingLocation]; 

    //[self.window addSubview:viewController.view]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    printf("\nerror"); 
} 
- (IBAction)showDirectionsToHere { 

    CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; // LINE 1 

    NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=old\%20Location&daddr=%f,%f", newLocation.latitude, newLocation.longitude];//Line 2 
} 

: 나는지도 내가 내 AppDelegate에 다음 코드를 추가했지만 그것은 나에게 오류를 제공 불렀다 버튼의 액션 (showDirectionsToHere)의 버튼 &을 추가 한 내 XIB에서 (showDirectionsHere) 라인 2에서 유효하지 않은 이니셜 라이저 의 오류가 발생하여 newLocation이 선언되지 않은 오류가 발생합니다. 도와주세요

답변

0

getCurrentLocation에 대한 코드를 게시하여 반환되는 결과를 볼 수 있습니까? 변수 newLocation이 선언되지 않습니다. 나는이 함수에서 currentLocation을 의미한다고 생각합니다.

+0

) showDirectionsToHere { CLLocationCoordinate2D currentLocation = 자기 getCurrentLocation]; // LINE 1 NSString * url = [NSString stringWithFormat : @ "http://maps.google.com/maps?saddr=old\%20Location&daddr=%f,%f", newLocation.latitude, newLocation.longitude] ; // Line 2 } getcurrentlocation은 LocationManager 객체를 반환합니다. – Rocky

+0

getCurrentLocation 메서드의 코드는 무엇입니까? – visakh7

+0

CLLocationCoordinate2D currentLocation = [self getCurrentLocation]; getCurrentLocation은 currentLocation에 저장된 CLLocationCoordinate2D 유형의 객체를 반환한다는 것을 의미합니다. 클래스를 수정하여 정확한 위치를 얻으십시오 – visakh7

2
NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=old\%20Location&daddr=%f,%f", currentLocation.latitude, currentLocation.longitude]; 
IBAction를
관련 문제