Coordinates Object
Coordinates are the smallest unit to represent geographical information such as the location of a camera or an overlay. Most APIs associated with maps deal with coordinates or areas as a parameter or return value.
Coordinates
The NAVER Maps SDK adopts the Geographic coordinate system that enables every location on the earth to be specified by a set of latitude and longitude as a default coordinate system, and provides associated features. The SDK also allows several other coordinate systems that can be converted into the default coordinate system.
NMGLatLng
NMGLatLng
is a class that represents a set of latitude and longitude. The lat
NMGLatLng(py)lat) property refers to a latitude, and the lng
NMGLatLng(py)lng) property refers to a longitude. All properties of the LatLng
class can only be specified by a constructor, and properties of the object once created cannot be modified.
The following code example creates an NMGLatLng
object and displays a latitude and longitude in the console.
let coord = NMGLatLng(lat: 37.5670135, lng: 126.9783740)
print("Latitude: \(coord.lat), Longitude: \(coord.lng)")
Swift
let coord = NMGLatLng(lat: 37.5670135, lng: 126.9783740)
print("Latitude: \(coord.lat), Longitude: \(coord.lng)")
Objective-C
NMGLatLng *coord = NMGLatLngMake(37.5670135, 126.9783740);
NSLog(@"Latitude: %f, Longitude: %f", coord.lat, coord.lng);
Other coordinate systems
The NAVER Maps SDK supports several coordinate systems other than the NMGLatLng
. The following coordinate systems are available:
WebMercatorCoord
: Coordinates in the Web Mercator coordinate systemUtmk
: Coordinates in the UTM-K coordinate systemTm128
: Coordinates in the TM-128 coordinate system
You can converts other coordinates into the LatLng coordinates by using the -toLatLng
method of each class, or vice versa by using a constructor that uses an NMGLatLng
as a parameter.
The following code example converts NMGUtmk
into NMGLatLng
.
let utmk = NMGUtmk(x: 953935.5, y: 1952044.1)
let latLng = utmk.toLatLng()
Swift
let utmk = NMGUtmk(x: 953935.5, y: 1952044.1)
let latLng = utmk.toLatLng()
Objective-C
NMGUtmk *utmk = NMGUtmkMake(953935.5, 1952044.1);
NMGLatLng *latLng = utmk.toLatLng();
The following code example converts NMGLatLng
into NMGUtmk
.
let latLng = NMGLatLng(lat: 37.5666103, lng: 126.9783882)
let utmk = NMGUtmk(from: latLng)
Swift
let latLng = NMGLatLng(lat: 37.5666103, lng: 126.9783882)
let utmk = NMGUtmk(from: latLng)
Objective-C
NMGLatLng *latLng = NMGLatLngMake(37.5666103, 126.9783882);
NMGUtmk *utmk = [NMGUtmk utmkFromLatLng:latlng];
MBR
With two coordinates representing south-western and north-eastern vertices respectively, you can create a rectangular shaped area. This is known as the Minimum bounding rectangle (MBR). MBRs are the simplest way to define an area, so they are frequently used by the APIs handling areas.
NMGLatLngBounds
NMGLatLngBounds
is a class that represents an MBR that consists of a pair of latitude and longitude. The southWest
NMGLatLngBounds(py)southWest) property refers to south west coordinates, and the northEast
NMGLatLngBounds(py)northEast) property refers to north east coordinates. All properties of the NMGLatLngBounds
class are readonly
, so each of them can be specified by a constructor, and properties of the object once created cannot be modified.
The following code example creates an NMGLatLngBounds
object.
let southWest = NMGLatLng(lat: 31.43, lng: 122.37)
let northEast = NMGLatLng(lat: 44.35, lng: 132)
let bounds = NMGLatLngBounds(southWest: southWest, northEast: northEast)
Swift
let southWest = NMGLatLng(lat: 31.43, lng: 122.37)
let northEast = NMGLatLng(lat: 44.35, lng: 132)
let bounds = NMGLatLngBounds(southWest: southWest, northEast: northEast)
Objective-C
NMGLatLng *southWest = NMGLatLngMake(31.43, 122.37);
NMGLatLng *northEast = NMGLatLngMake(44.35, 132);
NMGLatLngBounds *bounds = [NMGLatLngBounds latLngBoundsSouthWest:southWest northEast:northEast];