做了將近半年的ios開發,因爲一直忙於實現各種功能,都沒時間來記錄在工作中遇到的問題,現在工作量滿滿少下來,終於有時間來記錄一些編程中的疑難雜症了.
首先來說下AMapSearchKit,這是一個很鬱悶的東西,當初用高德做定位的時候,把2.6的sdk包全部下載下來了,包括AMapSearchKit,然後這個包一直沒用到,現在做poi功能的時候,使用了這個功能,然後就開始了一系列頭疼事情。http://lbsbbs.amap.com/forum.php?mod=viewthread&tid=7346&page=1#pid27882這是我高德論壇裏問高德技術的帖子。
這是高德定位sdk的下載地址: http://lbs.amap.com/api/ios-sdk/down/
網上有很多關於xcode運行的時候說frame找不到AMapSearchKit,有各種解決辦法,什麼刪掉AMapSearchKit,再關掉xcode,再清理driveData,再導入AMapSearchKit,還有些朋友是amap.bundle就夠了,不需要AMapSearchKit,後來我把原本的刪掉,再從官網上下載一個導入,清理後編譯就成功了。對於這個結果,我也是醉了。後來我把代碼上傳到svn,搭檔去更新代碼的時候,在他那邊又出現了找不到AMapSearchKit的問題,之前因爲沒有做記錄,所以我忘掉了是怎麼解決這個問題的,後來又一遍遍的嘗試,又通過重新下載AMapSearchKit解決了。也就是說上傳到svn可能損壞了文件。
接下來記錄下實現的過程,
1、設置開啓定位,成功後調用回調函數:
(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
//在這裏獲取到經緯度,然後把經緯度,你應用在高德上註冊的key上傳到高德的服務器,然後返回校正後的經緯度
NSDictionary* params = @{@"locations":[NSString stringWithFormat:@"%f,%f",lo,la],@"coordsys":@"gps",@"key":@"4872cd7c4e2*******5af9a432c4ef"};
AFHTTPClient* client = [[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:Urladdr]] ;
NSURLRequest* request = [client requestWithMethod:@"POST" path:@"http://restapi.amap.com/v3/assistant/coordinate/convert" parameters:params];
search = [[AMapSearchAPI alloc] initWithSearchKey:@"d2b556cd25f4007cd7419e36aa3a0b87" Delegate:self];
search.delegate = self;
//構造AMapReGeocodeSearchRequest對象,location爲必選項,radius爲可選項
AMapReGeocodeSearchRequest *regeoRequest = [[AMapReGeocodeSearchRequest alloc] init];
regeoRequest.searchType = AMapSearchType_ReGeocode;
regeoRequest.location = [AMapGeoPoint locationWithLatitude:la longitude:lo ];
regeoRequest.radius = 1000;
regeoRequest.requireExtension = YES;
//發起逆地理編碼
[search AMapReGoecodeSearch: regeoRequest];
}
這是開啓逆地理編碼後的回調函數
(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
//根據response.regeocode 處理,獲取你想得到的數據
}