問題描述
我正在嘗試使用以下代碼將地址地理編碼為坐標(biāo):
I am trying to geocode address into coordinates using following code:
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"6138 Bollinger Road, San Jose, United States" completionHandler:^(NSArray* placemarks, NSError* error){
for (CLPlacemark* aPlacemark in placemarks)
{
// Process the placemark.
NSString *latDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.latitude];
NSString *lngDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.longitude];
lblDestinationLat.text = latDest1;
lblDestinationLng.text = lngDest1;
}
}];
我已經(jīng)嘗試了很多次,但調(diào)試器從不進(jìn)入塊,我無法獲得位置.有人可以幫我嗎?
I have tried it many times but the debugger never enters the block and I am not able to get the location. Can someone please help me with it?
問候
潘卡伊
推薦答案
好吧,我發(fā)現(xiàn)我的錯(cuò)誤了.代碼是正確的并且工作完美.我一直在通過調(diào)試器處理它,并試圖找出調(diào)試器沒有進(jìn)入塊的原因.但是現(xiàn)在我發(fā)現(xiàn)調(diào)試器此時(shí)沒有進(jìn)入該塊.獲取位置值所需的時(shí)間很少.它是異步完成的,因此我無法找到它,并且由于崩潰后沒有值而導(dǎo)致崩潰.我已將代碼發(fā)布?jí)K移到塊內(nèi),現(xiàn)在一切正常.
All right I found my mistake. The code is correct and works perfect. All the while I was working on it was through debugger and was trying to figure out why the debugger did not enter the block. But now I have found out debugger does not enter the block at that moment. It takes little in getting the location values. It is done asynchronously so I was not able to find it and I was getting crash because of no values just after the crash. I have moved my code post block to inside the block and everything works fine for me now.
這篇關(guān)于將地址地理編碼為iphone中的坐標(biāo)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!