You need CARTO Enterprise or Enterprise trial account for Mobile SDK. Please contact us for an offer and free trials.
Registering your App
You must register all your mobile apps under your CARTO.com account settings. You’ll get the mobile app license code, which is needed for your app code. There are no limits how many apps you can register, and every platform (also Xamarin iOS and Xamarin Android) is regarded as separate app and needs separate registration.
4) In your app code connect to the MapView object and add a basemap layer
Following enables to load the MapView from the layout. The object itself was already created during the layout creation process, this step is specific to finding and referencing the MapView object in your request.
publicclassMainActivityextendsActivity{// make sure you replace the String value with the one from carto.com mobile app registration ! finalStringLICENSE="YOUR_LICENSE_KEY";privateMapViewmapView;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);// Register the license so that CARTO online services can be usedMapView.registerLicense(LICENSE);// Get 'mapView' object from the application layoutmapView=(MapView)this.findViewById(R.id.mapView);// Add basemap layer to mapViewCartoOnlineVectorTileLayerbaseLayer=newCartoOnlineVectorTileLayer(CartoBaseMapStyle.CARTO_BASEMAP_STYLE_VOYAGER);mapView.getLayers().add(baseLayer);}}
classMainActivity:AppCompatActivity(){// make sure you replace the String value with the one from carto.com mobile app registration ! valLICENSE="YOUR_LICENSE_KEY"varmapView:MapView?=nulloverridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.main);// Register the license so that CARTO online services can be usedMapView.registerLicense(LICENSE,this)// Get 'mapView' object from the application layoutmapView=findViewById(R.id.mapView)asMapView// Add basemap layer to mapViewvallayer=CartoOnlineVectorTileLayer(CartoBaseMapStyle.CARTO_BASEMAP_STYLE_VOYAGER)mapView?.layers?.add(layer)}}
5) Run the Android app
The map should appear with the default tyle. You can zoom, rotate, and tilt the map with touch.
6) Do something useful with the map - add a styled Marker for a point
1) Create new project. The simplest is to create a new ‘Single View application’ in your Xcode project
2) Configure Cocapod Podfile to load SDK to your project. If you do not use Cocoapod, then you can also load SDK and add as plain .framework to your project structure from the Mobile SDK Releases page.
3) Load/Update Cocoapods, and open .xcworkspace (instead of xcodeproj) to make use of Cocoapod. Run following in terminal, in your project folder
4) Modify Controller for Map View:
Replace YOUR_LICENSE_KEY with your Mobile App License API, see App Registration above.
In Objective-C apps you need some special tricks:
Extend ViewController and add MapView manipulation code into it. Ensure it is Objective C++, not plain Objective C class
Rename ViewController.m (comes with template) to ViewController.mm, to avoid Objective C++ compilation issues
Implement ViewController.h to extend GLKViewController, instead of UIViewController
in Swift apps you need one special trick:
Add YOURPROJECT.Swift-Bridging-Header.h to your project with simply one line:
The default storyboard template uses UIView class, you must use NTMapView class instead:
Open Main.Storyboard, select View Controller Scene > View Controller > View
From Navigator window, select Identity Inspector, change the first parameter (Custom Class) to NTMapView (from the default UIView).
Note: If you are using both iPhone (Main_iPhone.storyboard) or iPad (Main_iPad.storyboard) files for iOS, you must repeat the steps to change the default storyboard.
6) Run the iOS app
The map should appear with Voyager style, as defined in your ViewController. You can zoom, rotate, and tilt with multi-touch.
7) Add a Marker to the map to do something useful with the map
Each platform needs to be registered as its own app, and app UI is created separately. However, when executing API requests with the Mobile SDK, you can create one Xamarin project for Android and iOS and share the code. Some exceptions apply in regards to API calls which need Android context, or file system references. For example, the following API requests are platform specific:
Register license key: MapView.RegisterLicense()
Create package manager: new CartoPackageManager()
Almost all of the map related API code - such as adding layers and objects to map, handling interactions and clicks, etc. can be shared for iOS and Android through one project.
Xamarin Forms (version 3.3.0 and higher) support Native Controls. If you add Mobile SDK apps for iOS and Android platforms, Xamarin Native Controls is available by default. See the blog Embedding Native Controls into Xamarin.Forms for details.
While you can share most of code using Native Controls, you just need to specify the platform when creating the project:
Note: Native Controls only work if you create or update Form in the code, using the xaml definition will not work. This Xamarin development requirement is subject to change with each release. Mobile SDK with Xamarin Forms is currently in being tested with Native apps. .
b) Xamarin Android App
Follow these steps to add native apps to your Xamarin Android package.
1) Add MapView to your application main layout
2) Create MapView object, add a base layer
Load layout from a xml, and load the MapView from Layout. You can also create MapView with code. A definition of a base layer is enough for minimal map configuration.
c) Xamarin iOS App
Follow these steps to add apps to your Xamarin iOS package.
1) Add Map object to app view. When using Storyboards, use OpenGL ES View Controller (GLKit.GLKViewController) as a template for the map and replace GLKView with MapView as the underlying view class.
In the example below, it is assumed that the outlet name of the map view is Map.
2) Initiate map, set base layer
Add into MainViewController.cs:
Add Marker points to the map
This, as given before, is cross-platform code, covering both Xamarin and UWP:
:
Windows (UWP) native apps
Regardless of the name, CARTO Mobile SDK works also in Windows 10 desktop apps, assuming that they are created as modern UWP apps and not classic winapi apps.
Note: The UWP implementation of the Mobile SDK is experimental.
As app ID use same UUID as in your project’s Package.appmanifest > Packaging > Package name. For example, the sample app ID is c882d38a-5c09-4994-87f0-89875cdee539