Krutarth Patel
Krutarth Patel

Reputation: 3455

How to display Current lat long in ios?

Right now i am using MapKit in my application. i am getting lat long from web service but when i display in MapKit i am not getting lat long in MaKit in zoom. can you please tell me what is exact problem.

problem is in attachmentyou can see my location is not zoom

and here is my code

location.latitude =[lat floatValue];
 location.longitude =[lontd floatValue];
 CLLocationCoordinate2D cord= CLLocationCoordinate2DMake([lat floatValue],[lontd floatValue]);


MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:cord];
[annotation setTitle:@"My Place"];
[[self mapkit] addAnnotation:annotation];

//
    MKCoordinateRegion region =
       MKCoordinateRegionMakeWithDistance (
                                        location, 2000, 2000);
       [mapkit setRegion:region animated:NO];

can you please tell me why my pin is not zoom to lat long?

Upvotes: 1

Views: 357

Answers (1)

Uma Madhavi
Uma Madhavi

Reputation: 4917

Check the application on real device.The Simulator will always show you the default value for Latitude and Longitude.Make sure that the location services are enabled on your device.

Use this method to get current latitude & longitude

-(CLLocationCoordinate2D) getLocation {

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;

}

Upvotes: 1

Related Questions