tags:

views:

828

answers:

2

i want to get the GPS coordinates from iphone and send these GPS coordinates to web service. This web service, will take my GPS Coordinates and send me the location of the nearest ATM, from the current location. now i want to do this in 2 phases. First phase , i want to just send the GPS Coordinates to web service, and in return i want the address of the ATM location. Second phase , i want to point this ATM on the MAP displayed in iphone app.

I have the web service developed, which take 2 input parameters : lat and longi. and returns me the address of the ATM location in a string format.

To start with Phase 1 : Please help me with how to get the GPS cordinates and send it to the web service. so that i can just display the address in string format(Result i get from web service) on the view.

A: 
  1. Add CoreLocation framework to your project
  2. Create and setup an instance of CLLocationManager (e.g. set desiredAccuracy property)
  3. Set a delegate to your location manager
  4. In your delegate implement 2 methods: -didFailWithError and -didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
  5. Call -startUpdatingLocation on your location manager.

In didUpdate method you get all updates in your current location and can also check if the coordinates you get is valid for you (check horizontalAccuracy and timeStamp properties)

Vladimir
+1  A: 

This sample code from apple http://developer.apple.com/iphone/library/samplecode/LocateMe/index.html shows how to get coordinates from GPS, hope it helps

Daniel