使用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. 商業WPF應用程序的地圖
- 3. 我可以使用Lucene進行商業應用程序搜索嗎?
- 4. Appcelerator商店本地搜索
- 5. 在iPhone應用程序中使用mapkit
- 6. 谷歌地圖商業搜索
- 7. 德國應用程序商店(本地化)的iPhone應用程序
- 8. 爲Facebook創建本地商業應用程序
- 9. 如何在Android Google地圖應用程序中搜索商店?
- 10. iPhone應用程序位置搜索API
- 11. iphone/ipad企業應用程序發行
- 12. iPhone的iOS應該基於mapkit的應用程序看起來像iPhone原生地圖應用程序?
- 13. 如何在iPhone中執行Spotlight搜索
- 14. 使用Qt的商業應用程序
- 15. Google Maps API商業搜索
- 16. 分發iPhone應用程序的商業軟件產品
- 17. 在iOS上使用MapKit搜索地址
- 18. Bing GeoCode搜索API在Windows Phone應用程序中查找本地業務
- 19. 金融api爲iphone商業應用程序使用
- 20. 如何在從iPad搜索時搜索iPhone應用程序
- 21. iphone中的應用程序本地化
- 22. Unity製作的商業應用程序
- 23. 商業應用程序的TDD示例
- 24. 如何在iphone中執行搜索sdk
- 25. 實現Yelp商業照片到iPhone應用程序,如蘋果地圖
- 26. 如何大量銷售iPhone應用程序給商業客戶?
- 27. 在Android應用程序的Google地圖上執行硬編碼搜索
- 28. 直接從我的應用程序執行BLAST/SmithWaterman搜索
- 29. iPhone:本地應用程序與本地存儲的Web應用程序?
- 30. iPhone針對API XML執行搜索