我可以从下面的 locationManager 方法中找到当前用户 Lat/Longt。然后我需要将这些变量传递给 Google Places API 方法(如下所示)。我遇到的问题是ParseXML_of_Google_PlacesAP方法中的 myLat 和 myLongt 都有一个空值。但是,这些值在 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];
}
}