0

New to ios developement and need a little help. I am trying to use CoreLocation to load the users current location to a UITextField formatted as a Google Maps link ( http://maps.google.com/maps?q=loc:userLatitude,-userLongitude ) so I can share in sms.Can anyone suggest or point me to a example I can look at.

Please and Thanks.

Guess I'm not being clear enough.I want to use corelocation to pass the current lat and long to this string (http:/maps.google.com/maps?q=loc:currentLat,-currentLong) and load it to a UITextField. ie: if you were in Toronto the uitextField would have this link

http://maps.google.com/maps?q=loc:43.653433,-79.380341

For anyone thats interested I worked it out myself.

user1725650
  • 7
  • 1
  • 4
  • possible duplicate of [What parameters should I use in a Google Maps URL to go to a lat-lon?](http://stackoverflow.com/questions/2660201/what-parameters-should-i-use-in-a-google-maps-url-to-go-to-a-lat-lon) – progrmr Mar 16 '14 at 23:42
  • This is not a duplicate – user1725650 Mar 17 '14 at 18:01

1 Answers1

0
     #import "ViewController.h"

          @interface ViewController ()

        @property (strong, nonatomic) CLLocationManager *manager;

     @property (strong, nonatomic) IBOutlet UITextField *MyLocation;
    @property (strong, nonatomic) IBOutlet UILabel *addressLabel;

     @end

    @implementation ViewController

     - (void)viewDidLoad
          {
         [super viewDidLoad];
  [self startLocations];
              }

          - (void)didReceiveMemoryWarning
          {
            [super didReceiveMemoryWarning];
         // Dispose of any resources that can be recreated.
         }

          #pragma mark - Location Manager

         - (CLLocationManager *)manager {

        if (!_manager) {
    _manager = [[CLLocationManager alloc]init];
    _manager.delegate = self;
    _manager.desiredAccuracy = kCLLocationAccuracyBest;
        }
         return _manager;
          }

           - (void)startLocations {

          // create and start the location manager

         [self.manager startUpdatingLocation];
      }
        - (void)stopLocations {

           // create and start the location manager

           [self.manager stopUpdatingLocation];
         }
          - (void)locationManager:(CLLocationManager *)manager
        didFailWithError:(NSError *)error
     {
         NSLog(@"Error: %@", [error description]);
      }
    - (void)locationManager:(CLLocationManager *)manager 
             didUpdateLocations:(NSArray *)locations {



     // grab current location and display it in a label
       CLLocation *currentLocation = [locations lastObject];

   NSString *here = [
  NSString stringWithFormat:@"http://maps.google.com/maps?q=loc:
       %f,%f",currentLocation.coordinate.
         latitude,currentLocation.
   coordinate.longitude];
   self.MyLocation.text = here;

// and update our Map View
[self updateMapView:currentLocation];


}

  #pragma mark - Map Kit

  - (void)updateMapView:(CLLocation *)location {


// create an address from our coordinates
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks,
 NSError *error) 
   {
    CLPlacemark *placemark = [placemarks lastObject];
    NSString *address = [NSString stringWithFormat:@"%@, %@, %@, 
   %@, %@, %@",    placemark.subThoroughfare,placemark.
 thoroughfare, placemark.locality, placemark.administrativeArea,
 placemark.postalCode,placemark.
   ISOcountryCode];
    if (placemark.thoroughfare != NULL) {
        self.addressLabel.text = address;
    } else {
        self.addressLabel.text = @"";
    }
   }];
  [self stopLocations];}

    @end
user1725650
  • 7
  • 1
  • 4