IOS: difference between the location I get from CLLocationManager and MKMapView userLocation property

I have two view controllers: tweetViewController and MapViewController . The first is for the user to post a tweet, and in it I use CLLocationManager to get the user's location. When locationManager:didUpdateToLocation:fromLocation: , I got "locationA", I will remind the user that his location has been set.

A user can simply tweet with "locationA". Or change the location manually (if the location is not accurate enough) by clicking on the location information. In this case, the MapViewController and there is a drag-and-drop annotation pin associated with locationA that falls onto the map. I found a pin hundreds of meters from where I am. Then I set mapView.showUserLocation = YES . And I found that the location of the blue bubble is much more accurate than the pin. So my question is how can I get mapView userLocation in tweetViewController and not in place from CLLocationManager .

I am in China, I was looking for the same problem. Some people say that the map in China has been transformed, so an offset must occur. Any suggestion to solve the problem? Thanks in advance.

+4
source share
2 answers

Finally , I am using an instance of MKMapView to solve this problem.

Customization

mapView.showUserLocation = YES/NO; //to start/stop locating.

Using

 -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 

to get the location of the user. In my controller, mapView not displayed, it is used only to determine the location of the user, and the location is more accurate than what I get from locManager .

+2
source

CLLocationManager uses the same data in all of its instances. MKMapView uses internal CLLocationManager data. However, the decision to do what you want to do is to let MKMapView do its thing with respect to showUserLocation: At the same time, create an instance of CLLocationManager and its delegate.

Delegate messages will give you the GPS coordinate of the blue MKMapView pin. Everything will be synchronized with each other.

0
source

Source: https://habr.com/ru/post/1390216/


All Articles