MKMapView didUpdateUserLocation not updating - iphone

I have an application with map and want to zoom to the current location, when it's updated.
I use -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation delegate method to know when user location was updated.
Now on simulator method is being called as it should. But when i test it on device (iphone 2g) the location is updated on map, but "didUpdateUserLocation" method is not being called at all, same for delegate method "mapViewWillStartLocatingUser".
The system asks if I allow to get my location for app and starts showing my location, but
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
NSLog(#"didUpdateUserLocation = '%#'", userLocation);
}
is never called.

Reference mentions that this delegate method is available since iOS 4.0. Your simulator is most probably running iOS 4.0 while your phone - iOS 3.1.
I'm having the same problem and still looking for solution. Perhaps accessing CL methods directly will help.

try this Map.showsUserLocation=YES;

Related

stopUpdatingLocation is not working in iOS 7

I have developed both iPhone & iPad application which supports for iOS 5 and iOS 6
in that application i have grabbed user current location using CLLocationManager.
when i want to stop updating receiving GPS coordinates. I have called stopUpdatingLocation
method to stop calling didUpdateToLocation method. It was woking completely fine with iOS 5 and 6 But unfortunately its not working with iOS 7.
Seems that stopUpdatingLocation method is not working .Any particular reason. ??
i had a keep a variable to monitor the life cycle of didUpdateToLocation method and stop executes it.
One thing might be possible is,
Your current location blue dot moving on your map is because you set the MKMapView's showsUserLocation to YES. It will track until you set it to NO.
Second thing,
You might be setting below thing to stop calling that method
locationManager = nil;
That does not stop monitoring, but what it does, not to refer the location manager, So now its not possible to stop monitoring.
Instead add below code & then see what happen
[locationManager stopUpdatingLocation];
locationManager=nil;
Hope it helps..
#tdevoy - Here is sample
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
latitude = location.coordinate.latitude;
longtitude = location.coordinate.longitude;
//stops updating current user location update
[locationManager stopUpdatingLocation];
}

MKMapView crash on showUserLocation on iOS6

I just recently updated my iOS SDK to the latest release (6.0).
I used to have a couple of map views in my app, MKMapView, that were
used to show the user location.
After the update, upon setting the property
mapView.showUserLoaction = YES;
The app crashes with the following exception:
-[MKCoreLocationProvider locationManager:didUpdateToLocation:fromLocation:]: unrecognized
selector sent to instance 0x155af5f0
This happened on iPhone iOS 6.0 Simulator, not on device/simulators with previous versions of the OS.
The error can be reproduced just by setting the property. Otherwise the app run smooth.
The bug came up just after updating the SDK. Moreover, I didn't test on a iOS 6 device yet (all the test on such a device have been performed with the previous version of the SDK though, and the app didn't crash).
What could be the issue?
UPDATE: in iOS6 Device there are no issues. The problem appears just on the iOS 6 Simulator
Have you tried ?
[mapView setShowsUserLocation:YES];
if you are using a MKMapViewYou should also be using if you are doing something with the userlocation
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
}
I am using this delegate method and this is working fine for me in ios6
-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
}

Mapview refresh not working

I'm showing the route between 2 places. My project is a navigation based project. In the viewWillAppear: method I track the current location of the user using location manager. In the
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation method I get the coordinates of the user's current location.
I draw the map with this. Now when I get back to the previous view and come back map view it doesn't load the user location. It doesnt call - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation method.
How can I rectify this? I need to get the map route everytime I come to this class.
Thanks in advance
I am about to answer my own question with this as well:
I saw posts on how to reset the view, redraw the layer etc. I am fairly (not new) inexperienced with the language, so what I have done is a hack, but it works. I hope you use this if you have to, but find a better solution.
View Controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],2587600.0, 2587600.0);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
mapView.region = MKCoordinateRegionMakeWithDistance([mapView centerCoordinate],5.0, 5.0);
}
So when the view leaves, well... view, then the map zooms really far in. When the view returns to view, the the data is reloaded and voila. Your mileage may vary, but this method works perfectly for what I need it to do.
And it is not a jarring effect at all. It is seamless. From a UI standpoint, nothing changes.
cheers!
Robert

Iphone CLLocationManager horizontalAccuracy update. When? and how do I know it?

I need to display horizontalAccuracy of currentLocation on the map in my app. To do that I put a line of code in viewDidLoad();
(_currentLocation is CLLocationManager's location.)
label4Accuracy.text = [NSString stringWithFormat:#"Accuracy: %.fm", _currentLocation.horizontalAccuracy];
And it display's accuracy.
The problem is the accuracy does not change. The horizontalAccuracy changes its accuracy if we wait enough (not always though).
What I want my app to be able to do is that it changes the accuracy and display it on the map in real time.
I expected there might be a method somewhere near CLLocationManager like;
- (CLLocationAccuracy *)horizontalAccuracyUpdated():
but there isn't. So my question is where should I put the line of code above to display the horizontalAccuracy of currentLocation that changes in accordance to the actual device's current accuracy?
It's unclear from your question whether you're using your own CLLocationManager instance, or getting current location from an MKMapView.
If you're just using a MKMapView, your map view is going to make a delegate call to the method - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation every time it updates the user's location, and that userLocation variable it passes will have a .horizontalAccuracy parameter that gives the accuracy in meters.
So set your view controller as the map view's delegate and implement that method and watch there for updates.
If you're actually using a CLLocationManager, the same is true except the delegate method is - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation.

How to recenter map in iPhone app on zoom in/out using MKMapView

I am developing an iPhone application in which I need to show an image at a specific Latitude & Longitude on a Map. The requirement is - Even if the user zooms in or out on this map screen, the map control should automatically center itself after the zoom, to the same Lat & Long. I am using MKMapView.
I have tried to go through all available documentation. However, I could not come across any callback or other method that will allow me to achieve the objective.
One alternative is to handle touch events. However, I find that as a very complicated solution. And I hope that a simpler alternative exists. Any ideas on the above?
Can you please help? Any example will be appreciated.
Implement MKMapViewDelegate and then try this:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[mapView setCenterCoordinate:locationManager.coordinate animated:NO];
}
Replace locationManager with whatever the name of your CLLocationManager is.