以下の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];
}
}