This repository distributes a package rather than defining the complete product contract. Pair it with the owning SDK or product guide.
What this surface enables
Mappls UI Widget Native for iOS distributed via the SPM (Swift Package Manager).
The source identity names a capture, feedback, geofence, analysis, or guided-operation surface where provider calls and application-owned workflow state must be separated.
Authority: Source Identity · Evidence: ui-widgetiOS
MapsSearch PlacesRoutes NavigationTracking TelematicsWidgets Deep LinksCapture FeedbackIdentity Platform
SwiftText
No explicit authentication signal detected
Prepare the integration
- An iOS project with Xcode and the package manager required by the source release
- The corresponding product entitlement enabled for the developer application
Setup and usage examples
These examples were extracted from the canonical public source document and sanitized for credential-like values. Check the source branch and package version before copying into a production application.
import UIKit
import MapplsUIWidgets
class ViewController: UIViewController {
override func viewDidLoad() {
makeButton()
}
// Present the Autocomplete view controller when the button is pressed.
@objc func autocompleteClicked(_ sender: UIButton) {
let autocompleteController = MapplsAutocompleteViewController(theme: .auto)
autocompleteController.delegate = self
// Specify a filter.
let filter = MapplsAutocompleteFilter()
autocompleteController.autocompleteFilter = filter
// Display the autocomplete view controller.
present(autocompleteController, animated: true, completion: nil)
}
// Add a button to the view.
func makeButton() {
let btnLaunchAc = UIButton(frame: CGRect(x: 5, y: 150, width: 300, height: 35))
btnLaunchAc.backgroundColor = .blue
btnLaunchAc.setTitle("Launch autocomplete", for: .normal)
btnLaunchAc.addTarget(self, action: #selector(autocompleteClicked), for: .touchUpInside)
self.view.addSubview(btnLaunchAc)
}
}
extension ViewController: MapplsAutocompleteViewControllerDelegate {
// Handle the user's selection.
func didAutocomplete(viewController: MapplsAutocompleteViewController, withPlace place: MapplsAtlasSuggestion, resultType type: MapplsAutosuggestResultType) {
print("Place name: \(place.placeName)")
print("Place mapplsPin: \(place.mapplsPin)")
dismiss(animated: true, completion: nil)
}
func didAutocomplete(viewController: MapplsAutocompleteViewController, withFavouritePlace place: MapplsUIWidgetAutosuggestFavouritePlace) {
print("Place name: \(place.placeName)")
print("Place mapplsPin: \(place.mapplsPin)")
}
func didAutocomplete(viewController: MapplsAutocompleteViewController, withSuggestion suggestion: MapplsSearchPrediction) {
}
func didRequestForAutoSearchOptions(options: MapplsAutoSearchAtlasOptions) -> MapplsAutoSearchAtlasOptions {
return options
}
func didRequestForTextSearchOptions(options: MapplsTextSearchAtlasOptions) -> MapplsTextSearchAtlasOptions {
return options
}
func didFailAutocomplete(viewController: MapplsAutocompleteViewController, withError error: NSError) {
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
// User canceled the operation.
func wasCancelled(viewController: MapplsAutocompleteViewController) {
dismiss(animated: true, completion: nil)
}
// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(viewController: MapplsAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictions(viewController: MapplsAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}Operate the whole lifecycle
This operational model supplements the repository-level setup instructions. Adapt its resource names and transitions to the owning product contract.
Create a bounded application request or draft with purpose, policy, revision, and lifecycle owner before provider UI or capture begins.
Give one screen, controller, subscription, or callback generation explicit ownership of configuration, cancellation, timeout, and cleanup.
Treat provider output as a candidate; validate and copy a narrow portable value instead of persisting an opaque SDK or UI object.
Use application-owned versioning, idempotency, review, and audit when a candidate affects a durable business decision.
Stop listeners and native resources once, ignore late generations, and restore only application-owned state after restart.
Topics documented by the source
01Introduction
The MapplsUIWidgets SDK for iOS allows you can build rich apps by quickly implement reday made UI components. Currently this SDK have a widget for Searching a place using AutoSuggest API.
02Dependencies
This library depends upon several Mappls's own libraries. All dependent libraries will be automatically installed using CocoaPods.
Below are list of dependencies which are required to run this SDK:
• MapplsAPICore - MapplsAPIKit - MapplsMap - MapplsUIWidgets
03Installation
To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL. See Adding Package Dependencies to Your App.
04Dependencies
This library depends upon MapplsAPICore, MapplsAPIKit, MapplsMap. All dependent libraries will be automatically.
05MapplsAPICore
It is required to set Mappls keys to use any Mappls SDK. Please refer the documentation here.
06Autocomplete
The autocomplete service in the SDK for iOS returns place predictions in response to user search queries. As the user types, the autocomplete service returns suggestions for places such as businesses, addresses and points of interest.
You can add autocomplete to your app in the following ways:
Add an autocomplete UI control to save development time and ensure a consistent user experience.
Get place predictions programmatically to create a customized user experience.
07Add an autocomplete UI control
The autocomplete UI control is a search dialog with built-in autocomplete functionality. As a user enters search terms, the control presents a list of predicted places to choose from. When the user makes a selection, a MapplsAtlasSuggestion instance is returned, which your app can then use to get details about the selected place.
• Add a full screen control Add a results controller Use a table data source
08Add a full-screen control
Use the full-screen control when you want a modal context, where the autocomplete UI temporarily replaces the UI of your app until the user has made their selection. This functionality is provided by the MapplsAutocompleteViewController class. When the user selects a place, your app receives a callback.
To add a full-screen control to your app:
1. Create a UI element in your main app to launch the autocomplete UI control, for example a touch handler on a UIButton. 1. Implement the MapplsAutocompleteViewControllerDelegate protocol in the parent view controller. 1. Create an instance of MapplsAutocompleteViewController and assign the parent view controller as the delegate property. 1. Add a MapplsAutocompleteFilter to constrain the query to a particular type of place. 1. Present the MapplsAutocompleteViewController using [self presentViewController...]. 1. Handle the user's selection in the didAutocompleteWithPlace delegate method. 1. Dismiss the controller in the didAutocompleteWithPlace, didFailAutocompleteWithError, and wasCancelled delegate methods.
The following example demonstrates one possible way to launch MapplsAutocompleteViewController in response to the user tapping on a button.
09SwiftUI Full Screen Control
##### Create Autosuggest View Controller
1. In your project, add new SwiftUI View and name it MapplsAutocompleteViewControllerSwiftUIView.swift 2. In order to use native UIKit view controller in SwiftUI view, you must use UIViewControllerRepresentable wrapper. The instance of custom type which adopts UIViewControllerRepresentable protocol is responsible for creation and management a UIViewController object in your SwiftUI interface.
3. The UIViewControllerRepresentable requires to implement makeUIViewController(context:) method that creates the instance of with the desired UIKit view. Add the following code to create map view instance
4. The UIViewControllerRepresentable view also requires to implement updateUIViewController(:context:) which is used to configure the newly created instance. To show autosuggest only We dont need to configure anything so we will keep it empty.
5. To use selected place from results of autosuggest add below property code as shown above:
6. Use below code to create SwiftUIView to consume in another View.
10Add a results controller
Use a results controller when you want more control over the text input UI. The results controller dynamically toggles the visibility of the results list based on input UI focus.
To add a results controller to your app:
1. Create a MapplsAutocompleteResultsViewController. 1. Implement the MapplsAutocompleteResultsViewControllerDelegate protocol in the parent view controller and assign the parent view controller as the delegate property. 1. Create a UISearchController object, passing in the MapplsAutocompleteResultsViewController as the results controller argument. 1. Set the MapplsAutocompleteResultsViewController as the searchResultsUpdater property of the UISearchController. 1. Add the searchBar for the UISearchController to your app's UI. 1. Handle the user's selection in the didAutocompleteWithPlace delegate method.
There are several ways to place the search bar of a UISearchController into your app's UI:
• Add a search bar to the navigation bar Add a search bar to the top of a view
11Add a search bar to the navigation bar
The following code example demonstrates adding a results controller, adding the searchBar to the navigation bar, and handling the user's selection:
Note: For the search bar to display properly, your app's view controller must be enclosed within a UINavigationController.
12Add a search bar to the top of a view
The following code example shows adding the searchBar to the top of a view.
13Use a table data source
You can use the MapplsAutocompleteTableDataSource class to drive the table view of a UISearchDisplayController.
To use MapplsAutocompleteTableDataSource to display a search controller:
1. Implement the MapplsAutocompleteTableDataSourceDelegate and UISearchDisplayDelegate protocols in the parent view controller. 1. Create a MapplsAutocompleteTableDataSource instance and assign the parent view controller as the delegate property. 1. Create an instance of UISearchDisplayController. 1. Add the searchBar for the UISearchController to your app's UI. 1. Handle the user's selection in the didAutocompleteWithPlace delegate method. 1. Dismiss the controller in the didAutocompleteWithPlace, didFailAutocompleteWithError, and wasCancelled delegate methods.
The following code example demonstrates using the MapplsAutocompleteTableDataSource class to drive the table view of a UISearchDisplayController.
14Get place predictions programmatically
You can create a custom search UI as an alternative to the UI provided by the autocomplete widget. To do this, your app must get place predictions programmatically. Your app can get a list of predicted place names and/or addresses by using Mappls's library MapplsAPIKit. For more information Goto.
15MapplsAutocompleteFilter
This class represents a set of restrictions that may be applied to autocomplete requests. This allows customization of autocomplete suggestions to only those places that are of interest.
16Parameters:
A location to use as a hint when looking up the specified address.
This property prioritizes results that are close to a specific location, which is typically the user’s current location. If the value of this property is nil – which it is by default – no specific location is prioritized.
Zoom level to a location to use as a hint when looking up the specified address.
It allows to get tokenize address in response. By default its value is false. If value true is passed then only in response of MapplsAtlasSuggestion addressTokens will be recieved which is of type MapplsAddressTokens
On basis of this only specific type of Places in response will be returned.
Its data type is MapplsPodType which is derived from MapplsAPIKit
17Favourite Places
Favourite or Custom Places can be set to show in result of Autosuggest.
By default on searching by entering any text favourites will also be filtered. Filtering can be disabled by setting value false of global boolean property IsSearchFavouritesEnabled. By disabling it means it will always show favourites in results.
By default maximum two favourites will be shown in results. This can be configured by setting value of property FavouritesCountToShow. Its default value is 2. Minimum value can be 0 and maximum can be 10.
Below is line of code can be used to set favourite places.
Callback of selected favourite item can be handled using different delegate methods. See here.
18Theme
To change the theme of default search widget in the initilizer of MapplsAutocompleteViewController theme can set selected.
19Place Picker View
The Place Picker View is a UIView component that allows a user to pick a Place using an interactive map.
Users can select a location which from center of map after succesfully reverse geocoding that location.
PlacePickerView is class whose instance can be created and can be added to ViewController. Below is sample code to understand:
20PlacePickerViewDelegate
As from above sample code PlacePickerViewDelegate is a protocol class which provides different delegate methods which can be used according to requirements.
21Customize Place Picker
On adding instance of PlacePickerView it will load a default view with a map marker image on map But default view can be modified with help of some properties which are described as below:
View of marker on map can be ovrriden by using property 'markerView'. This is type of UIView so it can accept custom designed view and UIImageView as well.
isMarkerShadowViewHidden:
A shadow of marker is shows by defualt on dragging map. Visibility of this shadow can be changed by using property 'isMarkerShadowViewHidden'.
searchButtonBackgroundColor:
Background color of search button can be changed by using property 'searchButtonBackgroundColor'.
22Premium Features
The Place Picker widget has the capability to showcase certain premium features if they are provisioned within your project, like:
23Highlighting a Building
If the selected point on the map falls within a building, then Mappls Place Picker can also highlight the said building on the map. This visualization's color palette is configurable within the Mappls Map SDK.
In order to access this feature, please contact API support as well as your Business relationship manager.
Properties related to these feature are:
isBuildingFootprintEnabled:
This is a boolean property. By setting its value the ability to highlight the footprint of a building can be enabled or disabled if it is povisioned for your project.
buildingAppearance:
24MapplsAttributionsSettings
A class MapplsAttributionsSettings is exist which represents a set of settings that can be applied to autocomplete to control appearance (Content Length, Size, Horizontal Content Alignment and Vertical Placement) of attribution. Appearance of attribution on can be controlled by different properties of MapplsAttributionsSettings.
Service references found
URLs are sanitized during ingestion and may include documentation or legacy hosts. Use them to trace the source, not as a substitute for the current API contract.
https://www.mapmyindia.com/apihttps://about.mappls.com/api/advanced-maps/doc/autosuggest-api).https://github.com/mappls-api/mappls-ios-sdk/docs/v1.0.0/MapplsAPICore.mdhttps://github.com/mappls-api/mappls-ios-sdk/docs/v1.0.0/MapplsAPIKit.mdhttps://github.com/mappls-api/mappls-ios-sdk/docs/v1.0.0/MapplsMap.mdhttps://github.com/mappls-api/mappls-ios-sdk/docs/v1.0.0/MapplsUIWidgets.mdhttps://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app).https://developer.apple.com/documentation/swiftui/uiviewcontrollerrepresentablehttps://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/).https://www.mapmyindia.com/api/img/logos1/PhonePe.png)[](https://about.mappls.com/blog/)[](https://github.com/mappls-api)[https://www.npmjs.com/org/mapmyindiahttps://www.facebook.com/Mapplsofficial)[](https://twitter.com/mappls)[](https://www.linkedin.com/company/mappls/)[](https://www.youtube.com/channel/UCAWvWsh-dZLLeUU7_J9HiOAhttps://about.mappls.com/api/terms-&-conditions