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.
Code Block |
---|
|
//creates an NMMapCoordinates object representing London coordinates
NMMapCoordinates *mapCoordinates = [[NMMapCoordinates alloc] initWithLongitudeinitWithLatitude:-051.1257450833
andLatitudelongitude:51-0.5083312574];
//or, alternatively
NMMapCoordinates *mapCoordinates = [NMMapCoordinates mapCoordinatesWithLongitude 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.
Code Block |
---|
|
NMMapCoordinates *mapCoordinates1 = [[NMMapCoordinates alloc] initWithLatitude:51.50833
longitude:-0.12574];
NMMapCoordinates *mapCoordinates2 = [[NMMapCoordinates alloc] initWithLatitude:53.15785
andLatitude longitude:51.508331.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 throughout using initWithMinLongitude:minLatitude:maxLongitude:maxLatitude: and initWithLeftTop initWithTopLeft:andRightBottombottomRight: instance methods and mapRectangleFromCoordinates: class method. The later creates an NMMapRectangle surrounding all the coordinates passed as the argument.
Code Block |
---|
|
//creates an NMMapRectangle with four double values
NMMapRectangle *mapRectangle = [[NMMapRectangle alloc] initWithMinLongitude:minLongitude
minLatitude:minLatitude
maxLongitude:maxLongitude
maxLatitude:maxLatitude];
//or, alternatively
NMMapCoordinates *leftTop = [NMMapCoordinates mapCoordinatesWithLongitudemapCoordinatesWithLatitude:minLongitudemaxLatitude
andLatitude longitude:maxLatitudeminLongitude];
NMMapCoordinates *rightBottom = [NMMapCoordinates mapCoordinatesWithLongitudemapCoordinatesWithLatitude:maxLongitudeminLatitude
andLatitude longitude:minLatitudemaxLongitude];
NMMapRectangle *mapRectangle = [[NMMapRectangle alloc] initWithLeftTopinitWithTopLeft:leftTop
andRightBottom bottomRight:rightBottom]; |
Calculating bounding rectangle
Code Block |
---|
|
//creates an NMMapRectangle bounding all the coordinates in coordinatesArray
NMMapRectangle *mapRectangle = [NMMapRectangle mapRectangleFromCoordinates:coordinatesArray]; |
...