1

以下のlocationManagerメソッドから現在のユーザーLat/Longtを見つけることができます。次に、これらの変数をGoogle Places APIメソッド(以下にも示します)に渡す必要があります。私が抱えている問題は、ParseXML_of_Google_PlacesAPメソッドのmyLatとmyLongtの両方にnull値があることです。ただし、locationManagerメソッドでは値が正しく出力されます。

助けてくれてありがとう

- (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation
               fromLocation:(CLLocation *)oldLocation
    {
        int degrees = newLocation.coordinate.latitude;
        double decimal = fabs(newLocation.coordinate.latitude - degrees);
        int minutes = decimal * 60;
        double seconds = decimal * 3600 - minutes * 60;
        myLat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                         degrees, minutes, seconds];
        latLabel.text = myLat;
        degrees = newLocation.coordinate.longitude;
        decimal = fabs(newLocation.coordinate.longitude - degrees);
        minutes = decimal * 60;
        seconds = decimal * 3600 - minutes * 60;
        myLongt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                           degrees, minutes, seconds];
        longLabel.text = myLongt;


        NSLog(@"myLat is %@ myLongt is %@ from location mgr", myLat, myLongt);
    }


-(void)ParseXML_of_Google_PlacesAPI
{

    NSURL *googlePlacesURL=[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/xml?location=bar,@%&radius=500&types=bar&sensor=false&key=myAPIKey",myLat,myLongt]];

    NSLog(@"lat is %@ longt is %@", myLat, myLongt);

    NSData *xmlData = [NSData dataWithContentsOfURL:googlePlacesURL];
    xmlDocument = [[GDataXMLDocument alloc]initWithData:xmlData options:0 error:nil];

    NSArray *arr = [xmlDocument.rootElement elementsForName:@"result"];

    for(GDataXMLElement *e in arr )
    {
        [placesOutputArray addObject:e];
    } 
}
4

2 に答える 2

2

myLatとmyLongtはNSStringであり、値nullを示しているため、リリースされていることを意味します。

したがって、値をフィードした後、両方のオブジェクトを保持します。

 myLat = nil;
 myLat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                     degrees, minutes, seconds];
 [myLat retain];

また、

 myLongt = nil;
 myLongt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                       degrees, minutes, seconds];
 [myLongt retain];
于 2012-08-28T10:41:59.993 に答える
1

NSUserdefaultsに保存するだけです。したがって、あなたの場合は次のようになります。

[[NSUserDefaults standardUserDefaults] setValue:myLat forKey:@"currentLat"];
[[NSUserDefaults standardUserDefaults] setValue:myLongt forKey:@"currentLongt"];

そして、私はそれだけで好きなすべての方法からそれを読み返します:

NSString *currentLat = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentLat"];
NSString *currentLongt = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentLongt"];
于 2012-08-28T10:46:58.830 に答える