geocoding address into coordinates in iphone

后端 未结 3 751
迷失自我
迷失自我 2020-12-25 12:16

I am trying to geocode address into coordinates using following code:

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:@\         


        
相关标签:
3条回答
  • 2020-12-25 12:51

    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.

    0 讨论(0)
  • 2020-12-25 12:56

    Blocks are new features to Objective C from iOS4.0 onwards. A block you can imagine as a delegate method working in same functional block. As for any delegate method it takes time to invoke, depending upon the condition, same way block executes the code inside it, when it completes its work of geocoding. You can read more about Block in apples documentation or read http://www.raywenderlich.com/9438/how-to-use-blocks-in-ios-5-tutorial-part-2.

    You can also have look into my repository on GITHUB https://github.com/Mangesh20/geocoding

    0 讨论(0)
  • 2020-12-25 13:01

    I just ran that exact code and it worked as expected. Make sure that you have an active internet connection.

    Try adding a NSLog on the strings and see if it gets called.

    NSLog(@"lat: %@, lng: %@", latDest1, lngDest1);
    

    Are you running it in the simulator or the device?

    0 讨论(0)
提交回复
热议问题