Document Maps SDK for iOS Guides Utility Library Geometry Utilities

Geometry Utilities

The MAGeometry.h header file in the iOS Map SDK provides a variety of geometric calculation methods, including distance measurement, area calculation, coordinate conversion, and point-in-polygon or point-in-circle detection. This document introduces the most commonly used functions. For a complete reference, see MAGeometry.h.

Calculate the Straight-Line Distance Between Two Points

Calculate the straight-line distance (in meters) between two geographic coordinates.

// 1. Convert the two coordinates to map points
MAMapPoint point1 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(39.989612, 116.480972));
MAMapPoint point2 = MAMapPointForCoordinate(CLLocationCoordinate2DMake(39.990347, 116.480441));

// 2. Calculate the distance
CLLocationDistance distance = MAMetersBetweenMapPoints(point1, point2);

Check if a Point is Inside a Circle

Determine whether a given coordinate falls within a specified circular area. This is useful for implementing geofencing behavior. The function returns YES if the point is inside the circle, and NO otherwise.

CLLocationCoordinate2D location = CLLocationCoordinate2DMake(39.989612, 116.480972);
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(39.990347, 116.480441);
BOOL isContains = MACircleContainsCoordinate(location, center, 200);

Check if a Point is Within the Visible Map Area

Determine whether a given annotation's coordinate is currently visible on the map.

// 1. Convert the annotation's coordinate to a map point
MAMapPoint point = MAMapPointForCoordinate(annotation.coordinate);

// 2. Check if the point is within the visible map rect
BOOL isContains = MAMapRectContainsPoint(mapview.visibleMapRect, point);