0
votes

I have a mkmapview that i create at run time. First i have to tell that my actual problem is on the ipad but not on the simulator. On view did load i am calling two functions. fillValues and setDraggable Point.

CLLocationManager *locManager = [[CLLocationManager alloc]init];
[locManager startUpdatingLocation];

CLLocationCoordinate2D currCoordinates = locManager.location.coordinate;
NSLog(@"the latitude is %f",currCoordinates.latitude);
NSLog(@"the longitude is %f",currCoordinates.longitude);
[self fillLatitudeAndLongitudeTextFields:currCoordinates.latitude longitudeValue:currCoordinates.longitude];

[self setDraggablePinOnMap:currCoordinates];

ON SIMULATOR: logs the coordinates and fillTextfields and sets the draggable point on the map.The setDraggablePinOnMap method creates the map and sets the red annotation. So when the app loads on simulator it shows blue dot around my location and a red pin in the same location (Works as intended). I move the pin and get the coordinates of that location and update the textfields.

ON the device-iPAD First time i load up the app it loads up with my current location with a blue dot. But the red annotation instead of showing up at my current location it shows up at 0,0,0 and 0,0,0 at the center of earth on the equator. It is not doing as it was intended.Both the red and blue should intersect at the same point. Interesting point is on the second time load of this screen(basically i go back to screen A and come back to this screen.Lets say the screen where map is present as screen B) it loads the map with blue and red points intersecting. It is not able to do it only on the first time.Its like it was not able to figure out the location on the first load but can do it afterwards. How can I make it to show on the first load? Do i make sense?Please ask me if you need more information.

1

1 Answers

1
votes

It's not able to do it the first time because you haven't waited for the location manager to get a proper fix on your location. You need to make you class the location manager's delegate and wait for a didUpdateLocations callback. Once you get a location you can use it to set your red pin and then stop the location manager from sending you updates, or just ignore them if the pin has already been placed.