使用makkit框架开发iphone应用程序。我已将地图视图集成到应用程序中。想要使用一些api在某个地区执行搜索(本地搜索)的一些帮助,我试图探索谷歌java脚本API和ajax api,但不能指出我的解决方案任何帮助,将不胜感激。执行本地商业搜索的iphone mapkit应用程序
2
A
回答
4
下面是我用于谷歌搜索API的部分代码。 您需要访问Google Labs API并获取可用于搜索的密钥。 还有一个GData库,但是我很难将它用于本地搜索,所以我只是使用HTML/JSON版本。 我的代码告诉你如何开始解码返回的JSON,因为它做了一堆其他的东西,所以我切断了循环。
这是链接到Google AJAX APi。
我建议进行API调用,然后设置一个断点,您可以在这里查看JSON结果字典,以了解它的结构。
NSString *searchString =
[NSString stringWithFormat:@"http://ajax.googleapis.com/ajax/services/search/local?v=1.0&sll=%f,%f&q=%@",
currentLocation.establishedLocation.coordinate.latitude,
currentLocation.establishedLocation.coordinate.longitude,
searchTerms];
searchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // encode it
//NSString *localSearchResults = [NSString stringWithContentsOfURL:[NSURL URLWithString:searchString]];
NSError *error = nil;
NSString * localSearchResults = [NSString stringWithContentsOfURL:[NSURL URLWithString:searchString] encoding:NSUTF8StringEncoding error:&error];
if (error != nil) {
NSLog(@"Error retrieving map search results in ActivityLocationViewControler::lookupSearchTerms: ");
NSLog(@"%s %d %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__); // http://stackoverflow.com/questions/969130/nslog-tips-and-tricks/969272
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
else {
NSData *jsonData = [localSearchResults dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
// we now magically have an array of results from our search. Each result has a bunch of data.
NSArray *resultsArray = [[dictionary objectForKey:@"responseData"] objectForKey:@"results"] ;
//NSArray *resultsArray = [dictionary objectForKey:@"responseData"];
CLLocationCoordinate2D curCoordinate;
NSDictionary *currentResult;
BOOL skipThisEntry;
for (int i = 0; i < [resultsArray count]; i++) {
currentResult = [resultsArray objectAtIndex:i]; // this is a dictionary of this result
curCoordinate.latitude = [(NSString *) [currentResult objectForKey:@"lat"] doubleValue] ;
curCoordinate.longitude = [(NSString *) [currentResult objectForKey:@"lng"] doubleValue] ;
0
我刚刚发布了一些简单的iOS类,它们使用Google的Local Search API通过名称或地址搜索来获取有关地图区域中地点的位置信息。有detailed instructions here和the GitHub repository is here。
希望这些信息可以让新开发人员在iPhone应用程序中使用Google本地API非常容易获得其他地方的经纬度&经度&。
0
MapKit提供了MKLocalSearch API。
我们可以使用此API来执行搜索用户按名称,地址或类型(例如咖啡或剧院)描述的位置。
参考:
// Create and initialize a search request object.
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchText;
request.region = self.map.region;
// Create and initialize a search object.
MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
// Start the search and display the results as annotations on the map.
[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error)
{
NSMutableArray *placemarks = [NSMutableArray array];
for (MKMapItem *item in response.mapItems) {
[placemarks addObject:item.placemark];
//For Address
//NSDictionary *addressDict = item.placemark.addressDictionary;
}
[self.map removeAnnotations:[self.map annotations]];
[self.map showAnnotations:placemarks animated:NO];
}];
相关问题
- 1. iPhone MKMapView商业应用程序?
- 2. 我可以使用Lucene进行商业应用程序搜索吗?
- 3. 在iPhone应用程序中使用mapkit
- 4. 如何在Android Google地图应用程序中搜索商店?
- 5. iPhone应用程序位置搜索API
- 6. iphone/ipad企业应用程序发行
- 7. Google Maps API商业搜索
- 8. 使用Qt的商业应用程序
- 9. 在iOS上使用MapKit搜索地址
- 10. 分发iPhone应用程序的商业软件产品
- 11. 金融api为iphone商业应用程序使用
- 12. 如何在从iPad搜索时搜索iPhone应用程序
- 13. 商业应用程序的TDD示例
- 14. Unity制作的商业应用程序
- 15. iphone中的应用程序本地化
- 16. 如何在iphone中执行搜索sdk
- 17. 在Android应用程序的Google地图上执行硬编码搜索
- 18. 直接从我的应用程序执行BLAST/SmithWaterman搜索
- 19. 搜索Android应用程序的最佳供应商
- 20. 搜索Windows商店应用文本
- 21. 如何大量销售iPhone应用程序给商业客户?
- 22. 如何使用qrcode搜索执行市场应用程序
- 23. 如何使用应用程序栏执行搜索?
- 24. iPhone:本地应用程序与本地存储的Web应用程序?
- 25. iPhone针对API XML执行搜索
- 26. 安排iPhone应用程序执行
- 27. 从应用程序商店购买企业应用程序的应用程序
- 28. 作为本地应用程序运行的iPhone网络应用程序
- 29. Qt,LGPL,商业闭源应用程序
- 30. Directx应用程序商业分布