user885790
user885790

Reputation:

annotation on current location

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,

on top is the button on pressing which i get the location statically passed on second loop but on iPhone it won't works

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

Answers (2)

Sonu
Sonu

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.

http://pastebin.com/Vv1wvyBh

which may be helpful to you :)

Thanks.

Upvotes: 1

Tony
Tony

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

Related Questions