Xamarin NuGet Package >
Geo Augmented Markers for iOS

This tutorial will guide you through the creation of a simple Geo Localization application that display a list of point of interest either on smartphone/table camera or on Google Maps (2.2.0 version or greater).
Please note: our SDK support iOS SDK 10.2 or later. This tutorial refers to Pikkart AR SDK version 3.5+.

Prerequisites:

In order to use the iOS Geo SDK, you have to register on the Pikkart's web site and get a valid demo license. 
An 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 on the device before installing a new one. Let's see what needs to be done with regards to profiles and licensing when you're using the demo license.

  • A demo license is already provided in the project. It's the "license.spz" file in the "Resources" folder. You may want to keep it there for this example, but you will have to replace it with a valid license once you plan to ship your own app.
  • You will need to install Fastlane, if you haven't already done so, in order to configure code signing in Visual Studio. Please refer to this page for more information.

There are two issues at play here:
1) the demo license only allows the creation of apps whose Bundle Identifier is "com.pikkart.trial" and
2) that Bundle Identifier, which needs to be unique all over the world, is already registered by Pikkart, so you're not going to be able to register it to yourself for your apps

In layman terms this means you're not going to be able to specify the "com.pikkart.trial" Bundle Identifier and choose a Provisioning Profile that belongs to your own Apple developer profile and at the same time is linked to the "com.pikkart.trial" Bundle Identifier. We're going to solve this by using a Wildcard provisioning profile.

  • Open the project options and, in the "iOS Bundle Signing" section, choose your own signing identity and the Wildcard provisioning profile. Close the options window.
  • Open the Info.plist file. Under the "Identity" section check that the Bundle Identifier is "com.pikkart.trial", then under "Signing" make sure that automatic signing is turned off and your own team signing identity is selected.

You will also need to compile the Google Maps SDK for iOS, which you can get here (the tutorial was created using version 2.5.0 of such library) and import the compiled .framework files into the Xamarin project you can get here, whose code will be examined in this tutorial.
Note: during the compilation process you will need to provide your own Google Maps API Key, but if you don't already have one you will be taught how to obtain it in the Google web page for the project listed above.

It is now time to load the example project into Xamarin and examine it!

First, please note how the app declares its use of geolocalization services in the Info.plist file. This is mandatory unless you want to risk your app being rejected by Apple upon store publishing.

If you open the Info.plist file as text you will find these relevant elements:

<key>NSLocationWhenInUseUsageDescription</key>
<string>XamariniOS_GeoAugmentedMarker richiede accesso ai servizi localizzazione</string>
<key>NSMotionUsageDescription</key>
<string>PikkartGeoTutorial richiede accesso ai sensori di mobilità</string>
<key>NSCameraUsageDescription</key>
<string>XamariniOS_GeoAugmentedMarker richiede accesso alla fotocamera</string>
      

You can find the same information if you open the Info.plist file with Xamarin user interface, under the "source" tab.

The following NuGet packages are also required and provided with the example: Pikkart's own AR SDK and OpenTK

Now it's time to use Pikkart Geo funtionality. Open AppDelegate.cs file and replace the existing Google Maps API Key with your own.

In the same AppDelegate.cs file you will find a few interesting code bits, the first being the FinishedLaunching method:

Window = new UIWindow (UIScreen.MainScreen.Bounds); 
PKTGeoMainController.SetGoogleMapsKey(kGMapManagerGoogleMapsAPIKey); 
ViewController geoMain=new ViewController(new GeoViewMarkerAdapter(new CGSize(30,45)), new MapViewMarkerAdapter(new CGSize(40,40)));
Window.RootViewController=geoMain; 
Window.MakeKeyAndVisible(); 

Here we are replacing the standard View Controller with a custom one that will implement the geolocalization features that we want. The View Controller is implemented by the ViewController.cs class, which we will be analyzing below and that is included in the example.

This class constructor accepts two parameters in the form of two PKTMarkerViewAdapter instances. These, in turn, provide the GetView and GetSelectedView methods which return a representation, in the form of an image, of a geolocalization placeholder.

Why two instances though? That's because the app has two main modes in which it can work: when you hold the device parallel to the ground (map mode), a map will appear with placeholders pointing to a few selected points of interest (which you can customize in the ViewController.cs file). When you hold your phone vertically (AR mode), you will see your phone camera output with the placeholders superimposed in the general direction of the landmarks. Placeholders are different between map mode and AR mode.

Let's take a look at the ViewController.cs class. There we can find an implementation of the PKTGeoMainController class, which is able to perform either geolocalization or recognition features.

For this tutorial, we will disable recognition feature (using DisableRecognition() method) and it will enable geolocalization features (with EnableGeoAR() and EnableGeoMap() methods).

Now it's time to launch the app and check that it works both in map mode and in AR mode. If the provided landmarks appear too close to each other, feel free to replace them with others more relevant to your position.