KNMapView
INFO
This English reference is based on Directions SDK 1.12.12. For the latest version, see the Korean reference.
A View class that displays a map and provides Camera, Marker, route, and shape drawing features.
Properties
| Name | Description | Type |
|---|---|---|
isVisibleTraffic | Whether traffic information is displayed on the map [color info] Gray: Impassable or Unknown Blue: Smooth Yellow: Slow Orange: Delayed Red: Congested (default: NO) | @property (nonatomic, readwrite, assign) BOOL isVisibleTraffic |
isVisibleBuilding | Whether buildings are displayed on the map (default: YES) | @property (nonatomic, readwrite, assign) BOOL isVisibleBuildling |
coordinate | KATEC coordinates that indicate the location of the map set through moveCamera. | @property (nonatomic, readonly) FloatPoint coordinate |
anchor | Coordinates that indicate where on the screen the map location set through moveCamera is placed. Screen values are expressed as (x-axis, y-axis), where the top-left corner is (0, 0) and the bottom-right corner is (1, 1). Moving right adds +0.1 on the x-axis, and moving down adds +0.1 on the y-axis.Because this property is read-only, changing the coordinate values (x, y) has no effect. | @property (nonatomic, readonly) FloatPoint anchor |
bearing | The direction angle of the map set by moveCamera (unit: degrees) | @property (nonatomic, readonly) float bearing |
zoom | Zoom level of the map set by moveCamera. You can zoom the map in and out; a larger value zooms in further. | @property (nonatomic, readonly) float zoom |
tilt | Tilt of the map set by moveCamera (unit: degrees) | @property (nonatomic, readonly) float tilt |
mapTheme | Map theme (colors, day/night mode, and so on) | @property (nonatomic, readwrite, assign, nonnull) KNMapTheme* mapTheme |
viewEventListener | Event listener for Camera gestures (panning, Zoom, Tilt, and rotation) and touch gestures (single-tap and double-tap) | @property (nonatomic, readwrite, assign, nonnull) KNViewEventListener* viewEventListener: |
useTiltGesture | Whether the map tilt gesture is enabled. If NO, the tilt does not change even if you move two fingers vertically on the map.(default: YES) | @property (nonatomic, readwrite, assign) BOOL useTiltGesture |
useZoomGesture | Whether the map zoom gesture is enabled. If NO, pinching your fingers together or apart does not change the map scale.(default: YES) | @property (nonatomic, readwrite, assign) BOOL useZoomGesture |
useBearingGesture | Whether the clockwise/counterclockwise rotation gesture is enabled. If NO, the tilt of the screen does not change even if you move two fingers clockwise or counterclockwise on the map.(default: YES) | @property (nonatomic, readwrite, assign) BOOL useBearingGesture |
usePanningGesture | Whether the panning gesture, which moves the map quickly in one direction, is enabled. If NO, panning does not occur even if you move your finger quickly on the map.(default: YES) | @property (nonatomic, readwrite, assign) BOOL usePanningGesture |
userLocation | KATEC coordinates of the user location derived from the current GPS information | @property (nonatomic, readwrite, assign, nonnull) KNMapUserLocation* userLocation |
parkingLotProperties | Specify the Parking lot to be displayed in the map view. Register for KNMapParkingLotReceiver to receive a callback for the Parking lot event. | @property (readonly, nonnull) KNMapParkingLotProperties* parkingLotProperties; |
poiProperties | Specifies whether to display points of interest (POI) in the map view. Register KNMapPOIEventListener to receive POI events as callbacks. | @property (readonly, nullable) KNMapPOIProperties* poiProperties; |
routeProperties | Route display properties, including color and line width. Register KNMapRouteEventListener to receive route events. | @property (readonly, nullable) KNMapRouteProperties* routeProperties; |
isVisiblePOI(Deprecated) | Whether POI icons are displayed on the map (default: YES) | @property (nonatomic, readwrite, assign) BOOL isVisiblePOI |
routeTheme(Deprecated) | Route theme, including line width and color | @property (nonatomic, readwrite, assign, nonnull) KNMapRouteTheme* routeTheme |
Example code — KNMapView Example code for using the property
// Show traffic information on the map
self->mapView.isVisibleTraffic = YES;
BOOL isVisibleTraffic = self->mapView.isVisibleTraffic;
// Show buildings on the map
self->mapView.isVisibleBuilding = YES;
BOOL isVisibleBuilding = self->mapView.isVisibleBuilding;
// Set the map position in KATEC coordinates
FloatPoint currentCoordinate = self->mapView.coordinate;
// Set the screen coordinates where the map position is displayed
FloatPoint anchor = self->mapView.anchor;
// Set the bearing of the map
float bearing = self->mapView.bearing;
// Set the zoom level of the map
float zoom = self->mapView.zoom;
// Set the tilt of the map
float tilt = self->mapView.tilt;
// Set the map theme
self->mapView.mapTheme = [KNMapTheme driveDay];
KNMapTheme* currTheme = self->mapView.mapTheme;
// Register the event listener
mapView.viewEventListener = self;
// Register the marker event listener
mapView.markerEventListener = self;
// Disable zoom gestures on the map
self->mapView.useZoomGesture = NO;
BOOL useZoomGesture = self->mapView.useZoomGesture;
// Disable clockwise/counterclockwise tilt gestures
self->mapView.useBearingGesture = NO;
BOOL useBearingGesture = self->mapView.useBearingGesture;
// Disable panning gestures
self->mapView.usePanningGesture = NO;
BOOL usePanningGesture = self->mapView.usePanningGesture;
KNMapUserLocation* userLocation = self->mapView.userLocation;
userLocation.coordinate = self->mapView.coordinate; // Center position of the map
userLocation.icon = [UIImage imageNamed:@"plus.pdf"]; // Set the icon
userLocation.isVisible = true; // Whether to show
userLocation.angle = 45.0; // Rotation angle of the icon
userLocation.isVisibleGuideLine = true; // Guide line to the destination
userLocation.priority = 65535; // Priority
userLocation.guideLineColor = [UIColor blueColor];// Guide line color
// Icon pixel offset. Moves the icon up by 30 pixels and right by half its size.
userLocation.pixelOffset = IntPointMake(userLocation.icon.size.width * 0.5, -30);Constructor
TIP
KNMapView must be created through KNSDK.
KNMapView* mapView = [[KNSDK sharedInstance] makeMapViewWithFrame:[UIScreen mainScreen].bounds];Methods
setRoute
Sets a route on the map.
Example code — - setRoute:
// Route event delegation
- (void)guidanceGuideStarted:(KNGuidance *)aGuidance {
[mapView setRoute:aGuidance.routesOnGuide[0]]; // Draw the route on mapView
}- (void) setRoute: (KNRoute*) aRouteParameters
| Name | Description |
|---|---|
aRoute | The route. |
setRoutes
Receives a route list and Sets a route on the map.
Example code — - setRoute:
// Route event delegation
- (void)guidanceGuideStarted:(KNGuidance *)aGuidance {
[mapView setRoutes:aGuidance.routesOnGuide]; // Draw the route on mapView
}- (void) setRoutes: (NSArray<KNRoute*>*) aRoutesParameters
| Name | Description |
|---|---|
aRoutes | route list |
getRoutes
Returns the list of all routes set on the map.
Example code — - getRoutes
NSArray* routes = [self->mapView getRoutes];- (NSArray<KNRoute*>*) getRoutesremoveRoutesAll
Deletes all routes registered on the map.
- (void) removeRoutesAllsetZoomRangeWithMinimum:maximum
Sets the minimum and maximum Zoom levels. The server supports values from 0.1 through 9999.0; values outside this range are ignored.
Example code — - setZoomRangeWithMinimum:maximum:
[self->mapView setZoomRangeWithMinimum:aMinimum maximum:aMaximum];- (void) setZoomRangeWithMinimum: (float) aMinimum
maximum: (float) aMaximumParameters
| Name | Description |
|---|---|
aMinimum | Minimum Zoom level (0.1) |
aMaximum | Maximum Zoom level (9999.0) |
cullPassedRouteWithLocation:isAnimate
Trims the passed portion of the route using the provided KNLocation. If aIsAnimate is YES, the route is trimmed gradually over 500 ms. If NO, it is trimmed immediately.
Example code — - cullPassedRouteWithLocation:isAnimate:
// Route event delegation. Called when route guidance information or one or more of its detail items change.
- (void)guidance:(KNGuidance *)aGuidance didUpdateLocation:(KNGuide_Location *)aLocationGuide {
// Trim the traveled route based on the current position
[self->mapView cullPassedRouteWithLocation:aLocationGuide.location isAnimate:false];
}- (void) cullPassedRouteWithLocation: (KNLocation*) aLocation
isAnimate: (BOOL) aIsAnimateParameters
| Name | Description |
|---|---|
aLocation | Location information |
aIsAnimate | Whether to animate route trimming |
addMarker
Adds a marker to the map.
Example code — - addMarker:
// Current map position
FloatPoint pos = FloatPointMake(self->mapView.coordinate.x, self->mapView.coordinate.y);
// Create a default pin marker and add it to the map
KNMapMarker* marker = [KNMapMarker markerWithCoordinate:pos];
marker.priority = PRIORITY;
marker.tag = MARKER_01;
marker.info = nil;
// Set marker visibility by map zoom level
[marker setVisibleRangeWithMinZoom:0.1 maxZoom:30.0];
[self->mapView addMarker:marker];- (void) addMarker: (KNMapMarker*) aMarkerParameters
| Name | Description |
|---|---|
aMarker | Marker |
addMarkers
Adds a marker list to the map.
Example code — - addMarkers:
- (void)addMarkers:(NSArray*)aMarkers- (void) addMarkers: (NSArray<KNMapMarker*>*) aMarkersParameters
| Name | Description |
|---|---|
aMarkers | marker list |
removeMarker
Removes a marker from the map.
Example code — - removeMarker:
[self->mapView removeMarker:aMarker];- (void) removeMarker: (KNMapMarker*) aMarkerParameters
| Name | Description |
|---|---|
aMarker | Marker |
removeMarkersAll
Removes all markers added to the map.
Example code — - removeMarkersAll
[self->mapView removeMarkersAll];- (void) removeMarkersAllgetMarkers
Returns the list of markers added to the map. Returns an empty list if there are none.
Example code — - getMarkers
NSArray* markers = [self->mapView getMarkers];- (NSArray*) getMarkersaddCircle
Adds a circle to the map.
Example code — - addCircle:
IntPoint mapPos = [[KNSDK sharedInstance] convertWGS84ToKATECWithLongitude:127.11019081347423 latitude:37.3941851228957];
KNMapCircle *circle = [KNMapCircle circleWithCenter:FloatPointMake(mapPos.x, mapPos.y) radius:100.0f];
circle.strokeColor = [UIColor redColor];
circle.fillColor = [UIColor blueColor];
circle.strokeWidth = STROKE_WIDTH;
circle.strokeDashType = KNLineDashType_Solid;
circle.isVisible = YES;
circle.priority = PRIORITY;
circle.tag = CIRCLE_01;
[self->mapView addCircle:circle];- (void) addCircle: (KNMapCircle*) aCircleParameters
| Name | Description |
|---|---|
aCircle | Circle to add |
removeCircle
Removes a circle from the map.
Example code — - removeCircle:
[self->mapView removeCircle:aCircle];- (void) removeCircle: (KNMapCircle*) aCircleParameters
| Name | Description |
|---|---|
aCircle | Circle to remove |
removeCirclesAll
Removes all circles added to the map.
Example code — - removeCirclesAll
[self->mapView removeCircleAll];- (void) removeCirclesAllgetCircles
Returns the list of circles added to the map. Returns an empty list if there are none.
Example code — - getCircles
NSArray* circles = [self->mapView getCircles];- (NSArray*) getCirclesaddPolyline
Adds a polyline to the map.
Example code — - addPolyline:
ObjectLoader *objectLoader = [[ObjectLoader alloc] initWithFile:[[NSBundle mainBundle] pathForResource:@"testcase2.csv" ofType:nil]];
KNMapPolyline *mapPolyline = [KNMapPolyline polylineWithPoints:objectLoader.position countPoints:objectLoader.positionCnt];
mapPolyline.lineColor = [UIColor redColor];
mapPolyline.lineDashType = KNLineDashType_Solid;
mapPolyline.lineWidth = STROKE_WIDTH;
mapPolyline.isVisible = YES;
mapPolyline.priority = PRIORITY;
mapPolyline.tag = POLYLINE_01;
[self->mapView addPolyline:mapPolyline];aPolyline addPolyline: (KNMapPolyline*) aPolylineParameters
| Name | Description |
|---|---|
aPolyline | Polyline |
removePolyline
Removes a polyline from the map.
Example code — - removePolyline:
[self->mapView removePolyline:aPolyline];- (void) removePolyline: (KNMapPolyline*) aPolylineParameters
| Name | Description |
|---|---|
aPolyline | Polyline |
removePolylinesAll
Removes all polylines added to the map.
Example code — - removePolylinesAll
[self->mapView removePolylineAll];- (void) removePolylinesAllgetPolylines
Returns the list of polylines added to the map. Returns an empty list if there are none.
Example code — - getPolylines
NSArray* polylines = [self->mapView getPolylines];- (NSArray*) getPolylinesaddPolygon
Adds a polygon to the map.
Example code — - addPolygon:
ObjectLoader *objectLoader = [[ObjectLoader alloc] initWithFile:[[NSBundle mainBundle] pathForResource:@"testcase5.csv" ofType:nil]];
KNMapPolygon* polygon = [[KNMapPolygon alloc] polygonWithPoints:objectLoader.position countPoints:objectLoader.positionCnt];
polygon.fillColor = [UIColor redColor];
polygon.strokeColor = [UIColor greenColor];
polygon.strokeWidth = STROKE_WIDTH;
polygon.strokeDashType = KNLineDashType_Solid;
polygon.isVisible = YES;
polygon.priority = PRIORITY;
polygon.tag = POLYGON_01;
if(objectLoader.holeCnt > 0)
{
[polygon addHoleWithPoints:objectLoader.holePosition countPoints:objectLoader.holeCnt];
}
[self->mapView addPolygon:polygon];- (void) addPolygon: (KNMapPolygon*) aPolygonParameters
| Name | Description |
|---|---|
aPolygon | Polygon |
removePolygon
Removes a polygon from the map.
Example code — - removePolygon:
[self->mapView removePolygon:aPolygon];- (void) removePolygon: (KNMapPolygon*) aPolygonParameters
| Name | Description |
|---|---|
aPolygon | Polygon |
removePolygonsAll
Removes all polygons added to the map.
Example code — - removePolygonsAll
[self->mapView removePolygonAll];- (void) removePolygonsAllgetPolygons
Returns the list of polygons added to the map. Returns an empty list if there are none.
Example code — - getPolygons
NSArray* polygons = [self->mapView getPolygons];- (NSArray*) getPolygonsgetScreenRectWithRegion
Returns the screen rectangle (CGRect) that encloses KNMapCoordinateRegion.
Example code — - getScreenRectWithRegion:
// Get the minimum and maximum positions of Pangyo and Gwanghwamun
FloatPoint min, max;
min.x = MIN(self->pangyoPos.x, self->gwanghwamoonPos.x);
min.y = MIN(self->pangyoPos.y, self->gwanghwamoonPos.y);
max.x = MAX(self->pangyoPos.x, self->gwanghwamoonPos.x);
max.y = MAX(self->pangyoPos.y, self->gwanghwamoonPos.y);
// Move to the minimum/maximum area
KNMapCoordinateRegion* region = [KNMapCoordinateRegion regionWithMin:min max:max];
[self->mapView moveCamera:[KNMapCameraUpdate fitToRegion:region] withUserLocation:false];
// Get the CGRect of the area
CGRect rect = [self->mapView getScreenRectWithRegion:region];
NSLog(@"minMaxScreenRect orgin(x:%f, y:%f) size(width:%f height:%f)", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);- (CGRect) getScreenRectWithRegion: (KNMapCoordinateRegion*) aRegionParameters
| Name | Description |
|---|---|
aRegion | Received coordinate region |
isOverlappedWithScreenRect:region
Returns whether the screen rectangle (CGRect) overlaps KNMapCoordinateRegion.
Example code — - isOverlappedWithScreenRect:region:
// Add a marker
KNMapMarker* marker = [KNMapMarker markerWithCoordinate:FloatPointMakeWithIntPoint(self->gwanghwamoonPos)];
[self->mapView addMarker:marker];
marker.pixelOffset = IntPointMake(0, 10);
CGRect markerRect1 = [self->mapView getScreenRectWithRegion:[KNMapCoordinateRegion regionWithMarkers:[NSArray arrayWithObjects:marker, nil]]];
// Overlap check 1
if([self->mapView isOverlappedWithScreenRect:markerRect1 region:region]){
NSLog(@"routeMarkerOverlap marker isOverlap1");
}
else{
NSLog(@"routeMarkerOverlap marker isNotOverlap1");
}- (BOOL) isOverlappedWithScreenRect: (CGRect) aScreenRect
region: (KNMapCoordinateRegion*) aRegionParameters
| Name | Description |
|---|---|
aScreenRect | Screen rectangle (CGRect) |
aRegion | Received coordinate region |
isOverlappedWithScreenPoint:region
Returns whether the screen coordinate (CGPoint) overlaps KNMapCoordinateRegion.
Example code — - isOverlappedWithScreenPoint:region:
// Check whether a marker exists at an arbitrary position
NSArray* markers = [self->mapView getMarkers];
for(KNMapMarker* marker in markers){
if([self->mapView isOverlappedWithScreenPoint:point region:[KNMapCoordinateRegion regionWithMarkers:[NSArray arrayWithObject:marker]]]){
NSLog(@"overlaped markerTag %ld", (long)marker.tag);
}
}- (BOOL) isOverlappedWithScreenPoint: (CGPoint) aScreenPoint
region: (KNMapCoordinateRegion*) aRegionParameters
| Name | Description |
|---|---|
aScreenPoint | Screen coordinate (CGPoint) |
region | Received coordinate region |
moveCamera:withUserLocation
Updates the map camera position with the KNMapCameraUpdate settings.
Example code — - moveCamera:withUserLocation:
KNMapCameraUpdate* cameraUpdate = [[[[KNMapCameraUpdate targetTo:pos] zoomTo:zoom] tiltTo:tilt] bearingTo:bearing];
[self->mapView moveCamera:cameraUpdate withUserLocation:false];-(void) moveCamera: (KNMapCameraUpdate*) aCameraUpdate
withUserLocation: (BOOL) aWithUserLocationParameters
| Name | Description |
|---|---|
aCameraUpdate | KNMapCameraUpdate settings |
aWithUserLocation | Whether to synchronize the user location |
animateCamera:duration:withUserLocation
The information set to KNMapCameraUpdate is to change the current location on the map and to Zoom, the angles to aDuration for the time entered. (unit: ms)
Example code — - animateCamera:duration:withUserLocation:
KNMapCameraUpdate* cameraUpdate = [[[[KNMapCameraUpdate targetTo:pos] zoomTo:zoom] tiltTo:tilt] bearingTo:bearing];
[self->mapView animateCamera:cameraUpdate duration:1000 withUserLocation:false];-(void) animateCamera: (KNMapCameraUpdate*) aCameraUpdate
duration: (int) aDuraiton
withUserLocation: (BOOL) aWithUserLocationParameters
| Name | Description |
|---|---|
aCameraUpdate | KNMapCameraUpdate settings |
aDuraton | Animation duration(unit: ms) |
aWithUserLocation | Whether to synchronize the user location |
katecToScreen
Converts KATEC coordinates on the current map to screen coordinates.
Example code — - katecToScreen:
CGPoint screen = [self->mapView katecToScreen:marker.coordinate];- (CGPoint) katecToScreen: (FloatPoint) aKatecParameters
| Name | Description |
|---|---|
aKatec | KATEC coordinates |
screenToKatec
Converts screen coordinates on the current map to KATEC coordinates.
Example code — - screenToKatec:
FloatPoint katecPos = [self->mapView screenToKatec:CGPointMake(x, y)];- (FloatPoint) screenToKatec: (CGPoint) aScreenParameters
| Name | Description |
|---|---|
aScreen | screen coordinates |
addSegmentPolyline
Add a color dividing line to the map.
-(void) addSegmentPolyline: (KNMapSegmentPolyline*_Nonnull) aSegmentPolyline;Parameters
| Name | Description |
|---|---|
aSegmentPolyline | Color-segmented line |
removeSegmentPolyline
Remove the dividing line from the map.
-(void) removeSegmentPolyline: (KNMapSegmentPolyline*_Nonnull) aSegmentPolyline;Parameters
| Name | Description |
|---|---|
aSegmentPolyline | Color-segmented line |
removeSegmentPolylinesAll
Remove all the color dividing lines that have been added to the map.
-(void) removeSegmentPolylinesAll;getSegmentPolylines
Returns the colored partition line that has been added to the map. Returns the blank list if no colored partition line has been added.
-(NSArray*_Nullable) getSegmentPolylines;