Mapview refresh not working - iphone

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

Related

Is there a proper way to set the region of MKUserTrackingModeFollow?

In my code, I'm calling
- (IBAction)goToUserLocation:(id)sender {
[mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
which then has this callback
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// I then try to set the region in here, which doesnt always work. Sometimes it zooms into the user location, then zooms back out to the region I specify. Other times, it will just stay zoomed in.
}
The MKUserTrackingModeFollow zooms in far more than I would like. I'd like to be able to set it so that it zooms into a region I specify. Is there a proper way to do this or is the region of MKUserTrackingModeFollow set?
Thank you!
viewForAnnotation is completely the wrong place. That is called when ever the map decides it needs to draw an annotation on the map. The map may not need to redraw an annotation if it was already on screen when someone pressed the button to goToUserLocation.
Instead try setting the zoomed out region before the tracking mode is set or after the animation is done.

iOS how to keep current location center all the time

My map shows current location with blue dot..
Of course, when I move, blue dot moves.. I just want to keep blue dot center of the map all the time, making map's moving instead like Google map navigator..
I searched a lot but couldn't find the way...
In your map view delegate, do this:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
[mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
Try using mapView.userTrackingMode = MKUserTrackingModeFollow;, you'll get smoother panning than using the location manager manually.
In addition note that there is a ready-made button for managing the various tracking states:
MKUserTrackingBarButtonItem.
The easiest way would be to create a new UIView on top of your map's view with a blue dot and only move the map's view.

How to present Blue circle of current location in MKMapView iphone

I have an maps application in which I show the points of interest in the map using pins. I want to represent the current location with the blue circle which is shown in Google maps. Is there any way we can add it. Can any one please help me with this. I really appreciate your time.
Thanks
You can get this by specifying nil in the appropriate delegate method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation {
if (annotation == mapView.userLocation) {
return nil;
}
}
This should cause MKMapView to use the default, which should be the blue circle.
You should set the setShowsUserLocation: property of your map view to YES. This can be done programmatically or in Interface Builder. Be careful, as I believe the simulator still shows the user location in Cupertino, CA.
Also, if you continue tracking the user and their movements, the blue indicator will continue to move as they do.

how to handle navigation on map annotation bubble

I trying to create an application which will show some location on map. When i click on bubble with location name, i want to navigate to different view which will some information regarding the selected location
Can anyone guide me how to do that..
Thanx
#Umang why don't to you try adding a UIButton to the MKPinAnnotationView and give it a action that will be much easier. Navigate to diffetrent view by the action of UIButton......Please have a look on this tutorial and see how the UIImageView and UIButton is added to the MKPinAnnotationView
good Luck!
You can use MKMapView delegate method
- (void) mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control {
// navigate to view from here
}

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.