开发者

Mapview refresh not working

开发者 https://www.devze.com 2023-04-06 14:28 出处:网络
I\'m showing the route between 2 places. My 开发者_JS百科project is a navigation based project. In the viewWillAppear: method I track the current location of the user using location manager. In the

I'm showing the route between 2 places. My 开发者_JS百科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

0

精彩评论

暂无评论...
验证码 换一张
取 消