Displaying coordinates
Displays the KATEC coordinates of the current location.
-(void)showWGS84 {
// KATEC coordinates of the current location
FloatPoint currentPos = self->mapView.coordinate;
// Convert to WGS84 coordinates
DoublePoint wgs84Pos = [[KNSDK sharedInstance] convertKATECToWGS84WithX:currentPos.x y:currentPos.y];
// Print the message
NSString* msg = [NSString stringWithFormat:@"latitude(%f), longitude(%f)", wgs84Pos.y, wgs84Pos.x];
[self->listener alertView:msg];
}Adding a marker
You can configure a marker using the functions of the KNMapMarker (KO) class. You can change the marker image yourself, and if you do not set one, the marker is displayed with the default pin image.
-(void)addMarker {
// Current map position
FloatPoint pos = FloatPointMake(self->mapView.coordinate.x, self->mapView.coordinate.y);
// Create the marker with the default pin and add it to the map
KNMapMarker* marker = [KNMapMarker markerWithCoordinate:pos];
marker.priority = PRIORITY;
marker.tag = MARKER_01;
marker.info = nil;
// Set the zoom level range in which the marker is displayed on the map
[marker setVisibleRangeWithMinZoom:0.1 maxZoom:30.0];
[self->mapView addMarker:marker];
}Removing markers
You can delete the markers you added using the removeMarkersAll function of the KNMapView (KO) class.
-(void)removeMarker {
[self->mapView removeMarkersAll];
}Moving a marker
You can move the position of a marker with an animation effect using the functions of the KNMapMarker (KO) class.
static int flagMoveCoordinateMarker = 0;
-(void)moveCoordinateMarker {
IntPoint mapPos = [[KNSDK sharedInstance] convertWGS84ToKATECWithLongitude:127.110226 latitude:37.394259];
FloatPoint katecPos = FloatPointMakeWithIntPoint(mapPos);
// Get the markers
NSArray* markers = [self->mapView getMarkers];
int movingCase = flagMoveCoordinateMarker % 2;
// Move the position
for (KNMapMarker* marker in markers) {
if (movingCase == 0) {
// Basic move
marker.coordinate = katecPos;
} else if (movingCase == 1) {
// Move the marker position with an animation effect over 500 ms
[marker animateWithCoordinate:katecPos duration:500.0];
}
}
flagMoveCoordinateMarker++;
}Hiding and showing a marker
You can hide a marker or show it again using the functions of the KNMapMarker (KO) class.
-(void)showOrHideMarker {
// Get the markers
NSArray* markers = [self->mapView getMarkers];
// Hide/show the markers
for (KNMapMarker* marker in markers) {
marker.isVisible = !marker.isVisible;
}
}Adding a custom marker
You can change the marker image yourself using the functions of the KNMapMarker (KO) class.
-(void)addCustomMarker {
IntPoint mapPos = [[KNSDK sharedInstance] convertWGS84ToKATECWithLongitude:127.110226 latitude:37.394259];
// Marker icon
UIImage* icPin = [UIImage imageNamed:@"icPin00@3x.png"];
// Create the marker and add it to the map
KNMapMarker* customMarker = [KNMapMarker markerWithCoordinate:FloatPointMakeWithIntPoint(mapPos)];
customMarker.priority = PRIORITY;
customMarker.tag = MARKER_02;
customMarker.icon = icPin;
// The origin of icPin, a circular icon, is at the bottom center, so adjust the pixel offset so that the origin sits at the center of the circle
customMarker.pixelOffset = IntPointMake(0, icPin.size.height*0.5);
[self->mapView addMarker:customMarker];
}Fitting the screen to markers
Fits the screen to the markers you have set. The following is sample code that creates a fitInMarkers() function to fit the markers displayed on the map to the screen. It creates several markers around the current coordinates using random numbers, and then uses the KNMapCameraUpdate.fitToRegion() (KO) function to fit the initialized region on the screen with an animated camera.
-(void)fitInMarkers {
CGPoint screenPos = [self->mapView katecToScreen:self->mapView.coordinate];
for (int i = 0; i < 4; i++){
// Create a random screen position
CGPoint screenPoint = CGPointMake(screenPos.x + (float)(rand()%100), screenPos.y + (float)(rand()%100));
FloatPoint katecPoint = [self->mapView screenToKatec:screenPoint];
KNMapMarker* marker = [KNMapMarker markerWithCoordinate:katecPoint];
marker.priority = PRIORITY;
marker.tag = MARKER_03;
[self->mapView addMarker:marker];
}
// Get all markers
NSArray* markers = [mapView getMarkers];
// Create the marker region
KNMapCoordinateRegion* region = [KNMapCoordinateRegion regionWithMarkers:markers];
// Fit the screen with an animated camera over 0.5 seconds
[mapView animateCamera:[KNMapCameraUpdate fitToRegion:region] duration:500 withUserLocation:FALSE];
}Moving the user location
Moves the current user location to an arbitrary place and displays it.
The following is sample code that creates a moveUserLocation() function to set how the user location marker moves. Based on the value of flagMoveUserLocation, it changes the user location using one of three options: a basic move, an animated move, or a move synchronized with the camera. Each time the function is called, the value of flagMoveUserLocation increases by 1.
static int flagMoveUserLocation = 0;
-(void)moveUserLocation {
self->mapView.userLocation.isVisible = TRUE;
CGPoint screenPos = [self->mapView katecToScreen:self->mapView.coordinate];
// Create a random screen position
CGPoint screenPoint = CGPointMake(screenPos.x + (float)(rand()%150), screenPos.y + (float)(rand()%150));
// Random KATEC coordinates
FloatPoint katecPoint = [self->mapView screenToKatec:screenPoint];
int movingCase = flagMoveUserLocation%3;
if (movingCase == 0) {
// Basic move
self->mapView.userLocation.coordinate = katecPoint;
} else if (movingCase == 1) {
// Animated move. Rotates 45 degrees and moves over 500 ms
[self->mapView.userLocation animateWithCoordinate:katecPoint angle:45.0 duration:500.0];
} else if (movingCase == 2) {
// Move synchronized with the camera. The user location moves to the current position (KNMapView.coordinate)
[self->mapView animateCamera:[KNMapCameraUpdate targetTo:katecPoint] duration:500.0 withUserLocation:true];
}
flagMoveUserLocation++;
}Displaying a callout bubble on a marker
You can create a callout bubble to be displayed on a marker using the KNMapCalloutBubbleUpdate (KO) class. You can enter the title and subtitle of the callout bubble, and you can also set the font, font size, and font color.
// Display the marker callout bubble
-(void)showMarkerCalloutBubble {
KNMapCalloutBubbleUpdate* update = [KNMapCalloutBubbleUpdate calloutBubbleUpdate];
update = [[[[[[update
setTitle:@"주된 텍스트를 \n 표시합니다."]
setSubTitle:@"보조 텍스트를 표시합니다."]
setTitleFont: [UIFont boldSystemFontOfSize:32]]
setSubTitleFont: [UIFont systemFontOfSize:18]]
setTitleFontColor: [UIColor blackColor]]
setSubTitleFontColor: [UIColor grayColor]];
[marker updateCalloutBubble:update];
}