Because of China's national conditions, when marking and adding Annotation on MapView, there will always be a few hundred meters deviation from the actual GPS coordinates. Similarly, the address is also offset when reverse resolution is performed based on the GPS point.
MapView has a showsUserLocation attribute. When it is set to YES, a blue point is displayed on the map, marking the current position of the user. The location of the blue point is consistent with the actual location of the user. Apparently, MapView offsets the user's actual coordinates to display the correct position on the offset map. If you can get the coordinates of the blue point, and then compare with the actual GPS coordinates, you can get the Offset Value of the map at the current position.
MapView has a MKUserLocation attribute userLocation. Another attribute in this attribute is location, which is the coordinates after the blue point offset on the map. Compare the coordinates of the point with the actual coordinates of the user to get the offset value of the current position.
MKUserLocation also supports KVO. We only need to add a "location" Observer to continuously obtain the coordinates of the blue points, so that the offset value can be updated at any time as the user coordinates change.
The main code is as follows:
// First, add the following two rows to viewDidLoad // display my position point _ mapView. showsUserLocation = YES; // Add the "location" Observer [_ mapView. userLocation addObserver: self forKeyPath: @ "location" options :( NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context: nil]; // then, use CLLocationManager to obtain the actual coordinates of the user. //
Implement Observer
-(Void) observeValueForKeyPath :( NSString *) keyPath ofObject :( id) object change :( NSDictionary *) change context :( void *) context {// here is the coordinates after the offset, subtract from the actual coordinates of the user, that is, the coordinate offset value CLLocation * fakeloc = _ mapView of the current position. userLocation. location ;}