iOS SDK >
Geo Augmented Marker

This tutorial will guide you through the creation of a simple Geo Localization application that displays a list of points of interest, either on camera or on Google Maps (2.2.0 version or greater).  
Our SDK is designed for use with Xcode (versions 8.2 or later), and support iOS SDK 10.2 or later.

The complete Xcode project could be downloaded on github from this link. The following explanations are based on the code found there.
Please note that since we are using Cocoa Pods (more on this later), you should open the project by double clicking on the SDKSampleiOS_GeoAugmentedMarker.xcworkspace file, not the usual .xcodeproj file.
Another important thing to know for people who wish to use the demo license is that since you are limited to one bundle identifier for your apps (com.pikkart.trial), it is advisable to delete any app created with the Pikkart SDK before installing a new one.

Now it's time to enable Pikkart Geo SDK functionality! 

Open the ViewController.swift file: it is a subclass of Pikkart's Geo Controller Entry Point

class ViewController : PKTGeoMainController

Depending on Google Maps integration, you should provide some additional framework. In this tutorial Google Maps has been installed via CocoaPods.

Follow instruction from here on GoogleMaps reference guide. At the moment of writing this tutorial, we are using Google Maps 2.5.0

Points of Interest in Pikkart AR Geo SDK are implemented through the following classes: 

  • PKTGeoLocation includes information about geographic coordinates (latitude, longitude, altitude)
  • PKTGeoElement includes information about the point of interest, such as display name, id location and an imageSrc used to display an image associated to it.

The Point of Interest default user interface layout is described inside PKTGeoElementViewDefault.xib. In this tutorial we will simply use this layout for display a list of point of interest.

All is set, now you just have to start the geo localization process. You can do it (as in the example) in viewDidLoad method adding  geoelements using showGeoElements method of PKTGeoMainController class:



    internal func createPointOfInterests() {
        var geoLocation:PKTGeoLocation
        var geoElement:PKTGeoElement
        
        let poiNames=["COOP, Modena":CLLocationCoordinate2DMake(44.654894, 10.914749),
                      "Burger King, Modena":CLLocationCoordinate2DMake(44.653505, 10.909653),
                      "Piazza Matteotti, Modena":CLLocationCoordinate2DMake(44.647315, 10.924802)]
        var index = 0
        for (poiName, coord2D) in poiNames {
            geoLocation = PKTGeoLocation(latitudine: coord2D.latitude, andLongitudine: coord2D.longitude, andAltitudine: 0)
            if (poiName == "Burger King, Modena") {
                geoElement = PKTGeoElement(location: geoLocation, andIdLocation: "\(index)_"+poiName, andName: "", andVisibility:.ON_MAP)
            } else {
                geoElement = PKTGeoElement(location: geoLocation, andIdLocation: "\(index)_"+poiName, andName: "")
            }
            pointOfInterests.append(geoElement)
            index = index + 1
        }
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.createPointOfInterests()
        self.disableRecognition()
        self.setGeoElements(pointOfInterests)
    }

where self.pointOfInterests is an array of PKTGeoElement objects.

PKTGeoMainController exposes, via PKTIArGeoListener protocol, a list of override methods. We can use them in order to detect touch on single point of interest and to give feedback when user position changed:

  • This method is called each time the user position changes. It is possible to configure a minimun distance and time between two consecutive user position updates by calling the setLocationUpdateParametersMinTime() method of the PKTGeoMainController class .

 override open func onGeoLocationChanged(_ location: Any!)

  • This method is called when a touch on a single point of interest is made.
    override open func onGeoElement(_ geoElement: Any!, click view: UIView!)
  • This method is called every time a touch is detected on augmented view or google maps, but not on a point of interest  

 override open func onMapOrCameraClicked()

You can run the application now. If some point of interest is inside camera view, you should view the marker in augmented reality.

If you lays smarphone/tablet on a horizontal plane, Pikkart AR Geo display point of interests on Google Maps view.

Marker view customization

Starting from Pikkart iOS SDK 2.6.0, user can customize marker view used either in geolocazionation and maps using PKTMarkerViewAdapter class. This class has following interface:

open class PKTMarkerViewAdapter : NSObject  

public init!(size: CGSize)

open func getView(_ geoElement: PKTGeoElement!) -> UIView!  

open func getSelectedView(_ geoElement: PKTGeoElement!) -> UIView!

User can create a PKTMarkerViewAdapter using init!(size: CGSize) method, giving as input parameter CGSize of marker view.  You could override getView and getSelectedView method in order to provide custom marker view for normal and selected state, even associate different view for each geoElement. PKTGeoMainController uses PKTMarkerViewAdapter when it's created using following constructor:

public init!(geoMarkerViewAdapter geoViewAdapter: PKTMarkerViewAdapter!, andMapViewAdapter mapViewAdapter: PKTMarkerViewAdapter!)