Coordinates (v2.1.x – 2.2.x)

Coordinates (v2.1.x – 2.2.x)

Map coordinates

Geo locations in Navmii SDK is represented as NMMapCoordinates class instances. As expected, it has two properties: latitude (takes values from -90 to 90) and longitude (takes values from -180 to 180) . You can create NMMapCoordinates instances in two ways: via instance or class methods.

//creates an NMMapCoordinates object representing London coordinates NMMapCoordinates *mapCoordinates = [[NMMapCoordinates alloc] initWithLatitude:51.50833 longitude:-0.12574]; //or, alternatively NMMapCoordinates *mapCoordinates = [NMMapCoordinates mapCoordinatesWithLatitude:51.50833 longitude:-0.12574];

Calculating distance

An instance of NMMapCoordinates class can be used to calculate the distance between two pairs of coordinates using distanceTo: method.

NMMapCoordinates *mapCoordinates1 = [[NMMapCoordinates alloc] initWithLatitude:51.50833 longitude:-0.12574]; NMMapCoordinates *mapCoordinates2 = [[NMMapCoordinates alloc] initWithLatitude:53.15785 longitude:1.68682]; double distance = [mapCoordinates1 distanceTo:mapCoordinates2];

Rectangular area

Navmii SDK also has NMMapRectangle class representing a rectangle area on the map. It can be created using initWithMinLongitude:minLatitude:maxLongitude:maxLatitude: and initWithTopLeft:bottomRight: instance methods and mapRectangleFromCoordinates: class method. The later creates an NMMapRectangle surrounding all the coordinates passed as the argument.

//creates an NMMapRectangle with four double values NMMapRectangle *mapRectangle = [[NMMapRectangle alloc] initWithMinLongitude:minLongitude minLatitude:minLatitude maxLongitude:maxLongitude maxLatitude:maxLatitude]; //or, alternatively NMMapCoordinates *leftTop = [NMMapCoordinates mapCoordinatesWithLatitude:maxLatitude longitude:minLongitude]; NMMapCoordinates *rightBottom = [NMMapCoordinates mapCoordinatesWithLatitude:minLatitude longitude:maxLongitude]; NMMapRectangle *mapRectangle = [[NMMapRectangle alloc] initWithTopLeft:leftTop bottomRight:rightBottom];

Calculating bounding rectangle

//creates an NMMapRectangle bounding all the coordinates in coordinatesArray NMMapRectangle *mapRectangle = [NMMapRectangle mapRectangleFromCoordinates:coordinatesArray];