Search code examples
iphonecocoa-touchxcodeios-simulatorpositioning

how to determine current location from GPS in iphone


I needed to implement the positioning functionality in my next app. I got a few questions regarding the development. 1) I found the tutorial and implemented the positioning thing.. but is it possible to simulate my code with iphone simulator or is it necessary to use the device for this purpose. while googling i read on some forum that 4.2 SIM supports GPS apps simulation though it will give Apple's headquarter's location every time but in my case the CLLocationManager's didFailWithError delegate gets called. any help with that!!

2) After determining the position, longitude and latitude, how to determine the exact area name and other information from it?

Thanks in advance for your invaluable time and feedbacks.


Solution

  • CLLocationManager will in fact return the location of the network the simulator is using. It's MapKit that will think the current location is in Cupertino at Apple's headquarters. That you get two different locations from the calls often causes confusion.

    You can get information about a given latitude and longitude by using the MKReverseGeocoder. It will attempt to give you a full address, but you can use whatever portion of it you'd like (just the country, or city and state/province, whatever).