The simplest method for marking point correction in iOS MapView

Source: Internet
Author: User

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 ;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.