-4

我想开发一个可以找到最近的 ATM 的应用程序,我该如何设置这一切?找到您当前的位置并输入 ATM 位置。

4

2 回答 2

4

首先,您需要通过 CLLocationManager 类来帮助您获取当前位置

CLLocationManager *locationManager   =       [[CLLocationManager alloc]init];
 locationManager.delegate         =       self;
 [locationManager startUpdatingLocation];

以下代表将帮助您获取更新的位置

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

}

现在您可以使用 google place api 搜索当前坐标附近的任何事物

NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/xml?location=%f,%f&radius=%.0f&types=%@&sensor=true&key=AIzaSyDIWlL",currentlatitude,currentlongitude,distanceinmeters,itemYouWantToSearch];

// here you have to use your own key and change the ivars according to your need.

现在你必须使用 NSXMLParser 来解析数据

NSXMLParser *itemParser = [[NSXMLParser alloc]initWithContentsOfURL:[NSURL URLWithString:url]];
[itemParser setDelegate:self];
[itemParser parse];

以下解析器委托将帮助您获取数据

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict

{
 //opening tag
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
  //data of opening tag
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

//closing tag
}
于 2012-07-04T14:24:07.257 回答
0

首先,您必须阅读有关 XMLParsing、JSON Parsing 的所有内容。当您将了解有关解析的所有内容时,请转到下一步,这就是 API。在互联网上找到一个提供 ATM 详细信息的 URL...我建议您在 ATM 之前请使用 Google 的天气 API...这对初学者来说很容易。

于 2012-07-04T14:00:46.430 回答