Reputation:
I'm working on the project in which i added a button on pressing it should take me to my current location on map and should show the blue indicator to indicate the location,here is the code:
-(IBAction)gotoLocation
{
if(curntloc)
{
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.0112872;
mapRegion.span.longitudeDelta = 0.0112872;
[self.mapView setRegion:mapRegion animated: YES];
}
else
{
curntloc = [[CLLocation alloc] initWithLatitude:21.192415 longitude:72.821159];
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.0112872;
mapRegion.span.longitudeDelta = 0.0112872;
[self.mapView setRegion:mapRegion animated: YES];
}
}
This works fine on simulator you can see it in image,
but when i try to test it on iPhone it's getting crashed.what may be the possible reasons can any one point out? thanks
Upvotes: 4
Views: 710
Reputation: 957
First of all i want to tell you that from simulator you can't get current location. in your code you just used a static lat. long. and for the device i share a link just check.
which may be helpful to you :)
Thanks.
Upvotes: 1
Reputation: 4609
So I have found that with the iPhone it is a refresh issue for most of the MKMapView problems. I would suggest either resetting some properties of the map, recreating the map, or making sure that showing the user's location in the map_view is set. Resetting the properties of the map usually include something like location = map.centerCoordinate, map setCenter:location. Umm other then that I think that it could possibly be a memory issue? Something like an annotation being released at a wrong time or maybe the map itself is released?
Upvotes: 0