A custom High German map positioning blue point (user location accuracy circle)

In the development of some will encounter the use of maps, for high moral map of the current location of the blue point, according to the different effect of UI may need to achieve different effects, for instance the blue point for Avatar, network picture etc.. Here the high moral map of the current position of the “blue”, which makes the function more practical, more scalable.


Premise: has integrated the high moral map SDK, and set up AppKey, added the positioning authority related settings, here refer to the high moral map official documents.

1. First, we add a map to the view

- (void) creatMapView [[MAMapView {_mapView = alloc]initWithFrame:self.view.bounds]; _mapView.delegate = self; _mapView.showsCompass = NO; _mapView.showsUserLocation = YES; _mapView.userTrackingMode = MAUserTrackingModeFollow; _mapView.customizeUserLocationAccuracyCircleRepresentation = YES; [self.view addSubview:_mapView];}

Some basic properties are set here not much said, mainly to explain, if you need high German map display location information, you need to showUserLocation this property is set to YES, this property is set to YES, the user location information (including data location and direction change, equipment etc.) the following proxy method will be executed

#pragma mark MAMapViewDelegate (void) mapView: (MAMapView * mapView) didUpdateUserLocation: (MAUserLocation *) userLocation updatingLocation: (BOOL updatingLocation) {NSLog (@ "%d", updatingLocation); NSLog (@ "location update"); NSLog (@ location:%f,%f, userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude);}

From this callback method, we can obtain the current latitude and longitude information from time to time.

2, display the map position of the “blue”, custom blue point

Above, we have set _mapView.showsUserLocation to YES, and if you need to locate trace, you can set the property userTrackingMode to MAUserTrackingModeFollow, which is an enumeration.

If you need to / / map display and positioning of the blue point, you need the following two lines of code: _mapView.showsUserLocation = YES; _mapView.userTrackingMode = MAUserTrackingModeFollow;

To customize the blue point, need to be set to YES customizeUserLocationAccuracyCircleRepresentation attribute value

Whether the custom user / / position accuracy _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;

2.1 High German SDK provides the MAUserLocationRepresentation to modify the appearance of the blue point

Note: the following code / / excerpt from High German map open platform MAUserLocationRepresentation *r alloc] init] = [[MAUserLocationRepresentation; r.showsAccuracyRing = NO; / / / precision ring is displayed, the default YES r.showsHeadingIndicator = NO; / / / whether to display the direction indication (MAUserTrackingModeFollowWithHeading open). The default is YES r.fillColor = [UIColor redColor]; / / / precision circle fill color, the default kAccuracyCircleDefaultColor r.strokeColor [UIColor = blueColor]; / / / precision circle edge color, the default kAccuracyCircleDefaultColor r.lineWidth = 2; / / / precision circle line width, the default 0 r.enablePulseAnnimation = NO; whether the internal use of rhythm / / / blue dots effect, the default YES r.locationDotBgColor [UIColor = greenColor]; / / / location do not set the default white background color, r.locationDotFillColor = [UIColor grayColor]; / / / location of the blue dots of color, do not set the default blue R.Image imageNamed:@ = [UIImage "picture of you"]; / / / location icon, mutex and blue origin

You need to call a method after the settings above

[self.mapView updateUserLocationRepresentation:r];

The above methods can achieve the simple modification of the blue point, but scalability is not strong.

2.2 set up their own high moral map, blue point

Not set by MAUserLocationRepresentation, but the front position.

Whether the custom user location precision circle x (userLocationAccuracyCircle) corresponding to the view, the default is NO./n if YES: calls - (MAOverlayRenderer *) mapView (* MAMapView) mapView rendererForOverlay: (ID < MAOverlay> overlay Nil) if the return is not loaded,./n: if NO will use the default style. / be custom user the position precision of ring _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;

The above is the High German Api in the description, that is to say the customizeUserLocationAccuracyCircleRepresentation is set to YES, you can through the definition of the blue point.

The essence of the current position is also a pin, so we set it in the method of adding pins

- (MAAnnotationView *) mapView: (* MAMapView) mapView viewForAnnotation: (id< MAAnnotation> annotation) {/ / the current location of the user if pins ([annotation isKindOfClass:[MAUserLocation class]]) {static = NSString * userLocationStyleReuseIndetifier @ *annotationView = "userLocationStyleReuseIndetifier"; MAAnnotationView [mapView dequeueReusableAnnotationViewWithIdentifier:userLocationStyleReuseIndetifier]; if (annotationView = = Nil) {annotationView = "MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationStyleReuseIndetifier];} annotationView.canShowCallout = NO; annotationView.image = [UIImage imageNamed:@" heardImg "]; anno TationView.frame = CGRectMake (0, 0, 26, 26); annotationView.contentMode = UIViewContentModeScaleToFill; annotationView.layer.masksToBounds = YES; return annotationView;} / / other else if pin set ([annotation isKindOfClass:[MAPointAnnotation class]]) {static NSString = *locationBackViewReuseIndetifier @ *annotationView = "locationBackViewReuseIndetifier"; MAAnnotationView [mapView dequeueReusableAnnotationViewWithIdentifier:locationBackViewReuseIndetifier]; if (annotationView = = Nil) {annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:locationBackViewReuseIndetifier] annotationView.canShowCal;} Lout = NO; annotationView.image = [UIImage imageNamed:@ annotationView.frame = "heardImg_default"]; CGRectMake (0, 0, 10, 10); annotationView.contentMode = UIViewContentModeScaleToFill; annotationView.layer.masksToBounds = YES;} return nil;}

The above methods, as long as add to the map generated by this method will be a pin pin of the view, the current position is a pin, by judging if is the current position of the pin, we can define your own. In addition by the method of custom blue point, we can find out if you can have ideas together to discuss.

- (MAPolylineRenderer *) mapView: (* MAMapView) mapView rendererForOverlay: (id< MAOverlay> overlay) {/ * Custom positioning accuracy corresponding to MACircleView.*/ if (overlay = = mapView.userLocationAccuracyCircle) {return nil}};