Mappls API Kit (REST API Kit for iOS)
Introduction
Our APIs, SDKs, and live updating map data available for 200+ countries & territories give developers tools to build better experiences across various platforms.
You can get your api key to be used in this document here: https://apis.mappls.com/console/
The sample code is provided to help you understand the basic functionality of Mappls REST APIs working on iOS native development platform.
Installation
This library is available through CocoaPods
. To install, simply add the following line to your podfile
:
pod 'MapplsAPIKit', '2.0.1'
Run pod repo update && pod install and open the resulting Xcode workspace.
Dependencies](#Dependencies)
This library depends upon MapplsAPICore
. All dependent libraries will be automatically installed on using CocoaPods.
Getting Started
Mappls Map SDK for iOS lets you easily add Mappls Map and services to your own iOS app.It supports iOS SDK 9.0 and above and Xcode 10.1 or later. You can have a look at the map and features you will get in your own app by using the Mappls Map app for iOS. The SDK handles Map Display along with a bunch of controls and native gestures.
Authorization
MapplsAPICore
It is required to set Mappls keys and authenticate before using any Mappls SDK. Please see the reference here.
API Usage and Requirements
The allowed SDK hits are described on the plans page. Note that your usage is shared between platforms, so the API hits you make from a web application, Android app or an iOS app all add up to your allowed daily limit.
Autosuggest API
Get "type as you go" suggestion while searching for a location.
The Autosuggest API helps users to complete queries faster by adding intelligent search capabilities to your web or mobile app. This API returns a list of results as well as suggested queries as the user types in the search field.
For live demo click LIVE DEMO
The Autosuggest helps users to complete queries faster by adding intelligent search capabilities to your iOS mobile app. It takes a human readable query such as place name, address or Mappls Pin and returns a list of results.
Class used for Autosuggest search is MapplsAutoSuggestManager
. Create a MapplsAutoSuggestManager
object using your rest key or alternatively, you can place your rest key in the MapplsRestKey
key of your application's Info.plist file, then use the shared instance of MapplsAutoSuggestManager
class.
To perform auto suggest use MapplsAutoSearchAtlasOptions
class to pass query parameter to get auto suggest search with an option to pass region in parameter withRegion
, which is an enum of type MapplsRegionType
. If no value is passed for region, It will take default value which is India.
MapplsRegionType
is used to validate and get result for different countries availble with Mappls 200+ countries & territories
Additionally you can also set location and restriction filters in object of MapplsAutoSearchAtlasOptions
.
Request Parameters
- location: Location is required to get location bias autosuggest results.
- zoom: takes the zoom level of the current scope of the map (min: 4, max: 18).
- includeTokenizeAddress: On setting value of this property to true it provides the different address attributes in a structured object in response.
- pod: It takes place type which helps in restricting the results to certain chosen type
Below mentioned are the codes for the pod -- Sublocality
- Locality
- City
- Village
- Subdistrict
- District
- State
- Subsublocality
- filter: This helps you restrict the result either by mentioning a bounded area or to certain Mappls Pin. Below mentioned are both types whose instance can be set to this parameter -
- (a)
MapplsMapplsPinFilter
: to filter results on basis of Mappls Pin. - (b)
MapplsBoundsFilter
: to filter results on basis of geo bound. It accepts a value of typeMapplsRectangularRegion
.
- (a)
- hyperLocal: This parameter lets the search give results that are hyper-localized to the reference location passed in the location parameter. This means that nearby results are given a higher ranking than results far from the reference location. Highly prominent results will still appear in the search results, however they will be lower in the list of results. This parameter will work ONLY in conjunction with the location parameter.
- isBridgeEnabled: To get suggested searches in response. Value must be set
true
of this.
Response Parameters
In response of auto suggest search either you will receive an error or an object of MapplsAutoSuggestLocationResults
(derived from MapplsLocationResults
) which contains an array of MapplsAtlasSuggestion
(derived from MapplsSuggestion
) and an array of suggested searches of type MapplsSearchPrediction
.
Note: As class of response object will be derived from MapplsLocationResults
, You will need to cast it into MapplsAutoSuggestLocationResults
.
You will find below useful properties in suggestion object :
type: type of location POI or Country or City
mapplsPin: Mappls Pin of the location 6-char alphanumeric.
placeAddress: Address of the location.
latitude: Latitude of the location.
longitude: longitude of the location.
entranceLatitude: entry latitude of the location
entrancelongitude: entry longitude of the location
placeName: Name of the location.
orderIndex: the order where this result should be placed
addressTokens:
houseNumber: house number of the location.
houseName: house name of the location.
poi: name of the POI (if applicable)
street: name of the street. (if applicable)
subSubLocality: the sub-sub-locality to which the location belongs. (if applicable)
subLocality: the sub-locality to which the location belongs. (if applicable)
locality: the locality to which the location belongs. (if applicable)
village: the village to which the location belongs. (if applicable)
subDistrict: the sub-district to which the location belongs. (if applicable)
district: the district to which the location belongs. (if applicable)
city: the city to which the location belongs. (if applicable)
state: the state to which the location belongs. (if applicable)
pincode: the PIN code to which the location belongs. (if applicable)
Note: Values of latitude
, longitude
, entranceLatitude
and entrancelongitude
will depend upon claims provided on Keys
.
Code Samples
Objective C
MapplsAutoSuggestManager * autoSuggestManager = [MapplsAutoSuggestManager sharedManager];
// or
MapplsAutoSuggestManager *autoSuggestManager = [[MapplsAutoSuggestManager alloc] initWithRestKey:MapplsAccountManager.restAPIKey clientId:MapplsAccountManager.atlasClientId clientSecret:MapplsAccountManager.atlasClientSecret grantType:MapplsAccountManager.atlasGrantType];
MapplsAutoSearchAtlasOptions * autoSuggestOptions = [[MapplsAutoSearchAtlasOptions alloc] initWithQuery:@"mmi000" withRegion:MapplsRegionTypeIndia];
autoSuggestOptions.location = [[CLLocation alloc] initWithLatitude:28.2323234 longitude:72.3434123];
autoSuggestOptions.zoom = [[NSNumber alloc] initWithInt:5];
[autoSuggestManager getAutoSuggestionResultsWithOptions:autoSuggestOptions completionHandler:^(MapplsLocationResults * _Nullable locationResults, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if (locationResults) {
MapplsAutoSuggestLocationResults * results = (MapplsAutoSuggestLocationResults *) locationResults;
if(results && results.suggestions) {
for (MapplsAtlasSuggestion * suggestion in results.suggestions) {
NSLog(@"Auto Suggest %@%@", suggestion.latitude, suggestion.longitude);
}
}
if(results && results.suggestedSearches) {
for (MapplsSearchPrediction * suggestion in results.suggestedSearches) {
NSLog(@"Auto Suggest %@", suggestion.identifier);
}
}
} else {
NSLog(@"No Results");
}
}];
Swift
let autoSuggestManager = MapplsAutoSuggestManager.shared
//Or
let autoSuggestManager = MapplsAutoSuggestManager(restKey:
MapplsAccountManager.restAPIKey(), clientId:
MapplsAccountManager.atlasClientId(), clientSecret:
MapplsAccountManager.atlasClientSecret(), grantType:
MapplsAccountManager.atlasGrantType())
let autoSearchAtlasOptions = MapplsAutoSearchAtlasOptions(query: "mmi000",
withRegion: .india)
autoSearchAtlasOptions.location = CLLocation(latitude: 28.2323234, longitude: 72.3434123)
autoSearchAtlasOptions.zoom = 5
autoSuggestManager.getAutoSuggestionResults(autoSearchAtlasOptions) { (locationResults, error) in
if let error = error {
print("error: \(error.localizedDescription)")
} else if let locationResults = locationResults as? MapplsAutoSuggestLocationResults {
if let suggestions = locationResults.suggestions {
for suggestion in suggestions {
print("suggestion: \(suggestion.placeName)")
}
}
if let suggestions = locationResults.suggestedSearches {
for suggestion in suggestions {
print("suggestedSearches: \(suggestion.identifier)")
}
}
} else {
print("No Results")
}
}
For more details visit our api reference documentation.
Reverse Geocoding API
For live demo click LIVE DEMO
Gets the nearest address for a given lat long combination.
Reverse Geocoding is a process to give the closest matching address to a provided geographical coordinates (latitude/longitude). Mappls's reverse geocoding API provides real addresses along with nearest popular landmark for any such geo-positions on the map.
Class used for geocode is MapplsReverseGeocodeManager
. Create a MapplsReverseGeocodeManager
object using your rest key or alternatively, you can place your rest key in the MapplsRestKey
key of your application's Info.plist file, then use the shared instance of MapplsReverseGeocodeManager
class.
To perform the translation use MapplsReverseGeocodeOptions
class to pass coordinates as parameters to reverse geocode with an option to pass region in parameter withRegion
, which is an enum of type MapplsRegionType
. If no value is passed for region, It will take default value which is India.
MapplsRegionType
is used to validate and get result for different countries.
Response Parameters
In response of geocode search either you will receive an error or an array of MapplsGeocodedPlacemark
. Yo will find below useful properties in suggestion object:
- houseNumber: The house number of the location.
- houseName: The name of the location.
- poi: The name of the POI if the location is a place of interest (POI).
- poiDist: distance from nearest POI in metres.
- street: The name of the street of the location.
- streetDist: distance from nearest Street in metres.
- subSubLocality: The name of the sub-sub-locality where the location exists.
- subLocality: The name of the sub-locality where the location exists.
- locality: The name of the locality where the location exists.
- village: The name of the village if the location exists in a village.
- district: The name of the district in which the location exists.
- subDistrict: The name of the sub-district in which the location exists.
- city: The name of the city in which the location exists.
- state: The name of the state in which the location exists.
- pincode: The pin code of the location area.
- latitude: The latitude of the location.
- longitude: The longitude of the location.
- formattedAddress: The complete human readable address string that is usually the complete postal address of the result.
- areaCode: The area code of region.
- area: in-case the co-ordinate lies in a country the name of the country would be returned or if the co-ordinate lies in an ocean, the name of the ocean will be returned.
Code Samples
Objective C
MapplsReverseGeocodeManager * reverseGeocodeManager = [MapplsReverseGeocodeManager sharedManager];
//Or
MapplsReverseGeocodeManager * reverseGeocodeManager = [[MapplsReverseGeocodeManager alloc] initWithRestKey:MapplsAccountManager.restAPIKey];
MapplsReverseGeocodeOptions *revOptions = [[MapplsReverseGeocodeOptions alloc] initWithCoordinate:CLLocationCoordinate2DMake(28.553291, 77.258876) withRegion:MapplsRegionTypeIndia];
[reverseGeocodeManager reverseGeocodeWithOptions:revOptions completionHandler:^(NSArray<MapplsGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if (placemarks.count > 0) {
NSLog(@"Reverse Geocode %@",
placemarks[0].formattedAddress);
} else {
NSLog(@"No results");
}
}];
Swift
let reverseGeocodeManager = MapplsReverseGeocodeManager.shared
//Or
let reverseGeocodeManager = MapplsReverseGeocodeManager(restKey: MapplsAccountManager.restAPIKey())
let revOptions = MapplsReverseGeocodeOptions(coordinate: CLLocationCoordinate2D(latitude: 28.553291, longitude: 77.258876), withRegion: .india)
reverseGeocodeManager.reverseGeocode(revOptions) { (placemarks, attribution, error) in
if let error = error {
print("%@", error)
} else if let placemarks = placemarks, !placemarks.isEmpty {
print("Reverse Geocode: \(placemarks[0].formattedAddress)")
} else {
print("No results")
}
}
For more details visit our api reference documentation.
Nearby API
For live demo click LIVE DEMO
Nearby Places API, enables you to add discovery and search of nearby places by searching for a generic keyword used to describe a category of places or via the unique code assigned to that category.
Class used for nearby search is MapplsNearByManager
. Create a MapplsNearByManager
object using your rest key or alternatively, you can place your rest key in the MapplsRestKey
key of your application's Info.plist file, then use the shared instance of MapplsNearByManager
class.
To perform nearby search use MapplsNearbyAtlasOptions
class to pass keywords/categories and a reference location as parameters to get Nearby search results with an option to pass region in parameter withRegion
, which is an enum of type MapplsRegionType
. If no value is passed for region, It will take default value which is India.
MapplsRegionType
is used to validate and get result for different countries.
Additionally you can also set location and zoom in object of MapplsNearbyAtlasOptions
location coordinate can be set in comma seprated format i.e ("latitue", "longitue")
or location can be Mappls Pin for eg. ("MMI000")
Request Parameters
refLocation A location provides the location around which the search will be performed it can be coordinte (latitude, longitude) or Mappls Pin in
String
format.page: provides number of the page to provide results from.
sort: provides configured sorting operations for the client on cloud. Below are the available sorts:
- dist:asc & dist:desc - will sort data in order of distance from the passed location (default).
- name:asc & name:desc - will sort the data on alphabetically bases.radius (integer): provides the range of distance to search over (default: 1000, min: 500, max: 10000).
sortBy: It is used to sort results based on value provided. It can accept object of
MapplsSortBy
orMapplsSortByDistanceWithOrder
searchBy: It is used to search places based on preference provided. It is of enum type
MapplsSearchByType
its value can be either.importance
or.distance
filters: On basis of this only specific type of response returned. it can of type
MapplsNearbyKeyValueFilter
(derived fromMapplsNearbySearchFilter
). MapplsNearbySearchFilter have following properties.- **filterKey:-** It takes value for `key` to filter result.
- **filterValues:-** It takes an array of different query values.
- **logicalOperator:-** `logicalOperator` of enum `MapplsLogicalOperator` its default value is `and`.
``` swift
let filter = MapplsNearbyKeyValueFilter(filterKey: "brandId", filterValues: [String,String])
```
bounds (x1,y1;x2,y2): Allows the developer to send in map bounds to provide a nearby search of the geobounds. where x1,y1 are the latitude and langitude.
isRichData: It is of type
Bool
. It allows some additional information to receive inrichInfo
parameter of response.shouldExplain: It is of type
Bool
.userName: It is of type
String
. On basis of value of this some specific results bounded to a user.pod: It takes place type which helps in restricting the results to certain chosen type
Below mentioned are the codes for the pod -
- Sublocality
- Locality
- City
- Village
Response Parameters
You will find below useful properties in suggestion object :
- distance: provides the distance from the provided location bias in meters.
- mapplsPin: Mappls Pin, unique id of the location 6-char alphanumeric.
- email: Email for contact.
- entryLatitude: latitude of the entrance of the location.
- entryLongitude: longitude of the entrance of the location.
- keywords: provides an array of matched keywords or codes.
- landlineNo: Email for contact.
- latitude: Latitude of the location.
- longitude: longitude of the location.
- mobileNo : Phone number for contact.
- orderIndex: the order where this result should be placed
- placeAddress: Address of the location.
- placeName: Name of the location.
- type: Type of location POI or Country or City.
- city: Name of city.
- state: Name of state
- pincode: Pincode of area.
- categoryCode: Code of category with that result belongs to.
- richInfo: A dictionary object with dynamic information
- hourOfOperation: A string value which describes hour of operation.
- addressTokens:
- houseNumber: house number of the location.
- houseName: house name of the location.
- poi: name of the POI (if applicable)
- street: name of the street. (if applicable)
- subSubLocality: the sub-sub-locality to which the location belongs. (if applicable)
- subLocality: the sub-locality to which the location belongs. (if applicable)
- locality: the locality to which the location belongs. (if applicable)
- village: the village to which the location belongs. (if applicable)
- subDistrict: the sub-district to which the location belongs. (if applicable)
- district: the district to which the location belongs. (if applicable)
- city: the city to which the location belongs. (if applicable)
- state: the state to which the location belongs. (if applicable)
- pincode: the PIN code to which the location belongs. (if applicable)
- pageInfo:
- pageCount
- totalHits
- totalPages
- pageSize
Code Samples
Objective C
MapplsNearByManager * nearByManager = [MapplsNearByManager sharedManager];
//Or
MapplsNearByManager * nearByManager = [[MapplsNearByManager alloc] initWithRestKey:MapplsAccountManager.restAPIKey clientId:MapplsAccountManager.atlasClientId clientSecret:MapplsAccountManager.atlasClientSecret grantType:MapplsAccountManager.atlasGrantType];
NSString *refLocation = @"28.550667, 77.268959";
MapplsNearbyAtlasOptions *nearByOptions = [[MapplsNearbyAtlasOptions alloc] initWithQuery:@"EV Charging" location:refLocation withRegion:MapplsRegionTypeIndia];
[nearByManager getNearBySuggestionsWithOptions:nearByOptions completionHandler:^(MapplsNearbyResult * _Nullable result, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if (result.suggestions.count > 0) {
NSLog(@"Nearby %@", result.suggestions[0].placeAddress);
} else {
NSLog(@"No results");
}
}];
Swift
let nearByManager = MapplsNearByManager.shared
//Or
let nearByManager = MapplsNearByManager(restKey: MapplsAccountManager.restAPIKey(), clientId: MapplsAccountManager.atlasClientId(), clientSecret: MapplsAccountManager.atlasClientSecret(), grantType: MapplsAccountManager.atlasGrantType())
var refLocations: String!
refLocations = "28.543014, 77.242342"
let filter = MapplsNearbyKeyValueFilter(filterKey: "brandId", filterValues: ["Brand1", "Brand2"])
let sortBy = MapplsSortByDistanceWithOrder(orderBy: .ascending)
let nearByOptions = MapplsNearbyAtlasOptions(query:"EV Charging" , location: refLocations, withRegion: .india)
nearByOptions.filters = [filter]
nearByOptions.sortBy = sortBy
nearByOptions.searchBy = .importance
nearByManager.getNearBySuggestions(nearByOptions) { (result, error) in
if let error = error {
print("\(error.localizedDescription)")
} else if let result = result, let suggestions = result.suggestions, !suggestions.isEmpty {
print("Near by: \(suggestions[0].placeAddress)")
} else {
print("No results")
}
}
NearBy using Mappls Pin
Code Samples
let nearByManager = MapplsNearByManager.shared
//Or
let nearByManager = MapplsNearByManager(restKey: MapplsAccountManager.restAPIKey(), clientId: MapplsAccountManager.atlasClientId(), clientSecret: MapplsAccountManager.atlasClientSecret(), grantType: MapplsAccountManager.atlasGrantType())
let nearByOptions = MapplsNearbyAtlasOptions(query: "Shoes", location: "MMI000", withRegion: .india)
nearByManager.getNearBySuggestions(nearByOptions) { (result, error) in
if let error = error {
print(error.localizedDescription)
} else if let result = result, let suggestions = result.suggestions, !suggestions.isEmpty {
print("Near by: \(suggestions[0].placeAddress)")
} else {
print("No results")
}
}
For more details visit our api reference documentation.
Place Detail
The Mappls Pin is a simple, standardised and precise PAN India digital address system. Every location has been assigned a unique digital address or an Mappls Pin. The Place Detail can be used to extract the details of a place with the help of its Mappls Pin i.e. a 6 digit code.
Class used for Mappls Pin search is MapplsPlaceDetailManager
. Create a MapplsPlaceDetailManager
object using your authenticated Mappls's keys or alternatively, you can use the shared instance of MapplsPlaceDetailManager
class.
To perform Place Detail use MapplsPlaceDetailOptions
class to pass digital address code (Mappls Pin) as parameters to get detail result with an option to pass region in parameter withRegion, which is an enum of type MapplsRegionType
. If no value is passed for region, it will take default value which is India.
Response Parameters
In response of Mappls Pin search either you will receive an error or an object of MapplsPlaceDetail
.
- mapplsPin: The Mappls Pin assigned for a place in map database. A Mappls Pin is the digital identity for an address or business to identify its unique location.
- latitude: The latitude of the location.
- longitude: The longitude of the location.
- houseNumber: The house number of the location.
- houseName: The name of the location.
- poi: The name of the POI if the location is a place of interest (POI).
- street: The name of the street of the location.
- subSubLocality: The name of the sub-sub-locality where the location exists.
- subLocality: The name of the sub-locality where the location exists.
- locality: The name of the locality where the location exists.
- village: The name of the village if the location exists in a village.
- district: The name of the district in which the location exists.
- subDistrict: The name of the sub-district in which the location exists.
- city: The name of the city in which the location exists.
- state: The name of the state in which the location exists.
- pincode: The pin code of the location area.
- type: defines the type of location matched (HOUSE_NUMBER, HOUSE_NAME, POI, STREET, SUB_LOCALITY, LOCALITY, VILLAGE, DISTRICT, SUB_DISTRICT, CITY, STATE, SUBSUBLOCALITY, PINCODE)
- keyInfo: The dynamic custom information related to a place.
Note: Not all response parameters are available by default. These parameters are available on demand as per mutually agreed use case. For details, please contact Mappls API support.
Code Samples
Objective C
MapplsPlaceDetailManager * placeDetailManager = MapplsPlaceDetailManager.shared
//or
MapplsPlaceDetailManager * placeDetailManager = [[MapplsPlaceDetailManager alloc] initWithRestKey:MapplsAccountManager.restAPIKey clientId:MapplsAccountManager.atlasClientId clientSecret:MapplsAccountManager.atlasClientSecret grantType:MapplsAccountManager.atlasGrantType];
MapplsPlaceDetailOptions * placeOptions = [[MapplsPlaceDetailOptions alloc] initWithMapplsPin:@"mmi000" withRegion:MapplsRegionTypeIndia];
[placeDetailManager getResultsWithOptions:placeOptions completionHandler:^(MapplsPlaceDetail * _Nullable placeDetail, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if(placeDetail) {
NSLog(@"Place DetailL: %@", placeDetail.address);
} else {
NSLog(@"No results");
}
}];
#### Swift
```swift
let placeDetailManager = MapplsPlaceDetailManager.shared
let placeOptions = MapplsPlaceDetailOptions(mapplsPin: "mmi000", withRegion: .india)
placeDetailManager.getResults(placeOptions) { (placeDetail, error) in
if let error = error {
print(error)
} else if let placeDetail = placeDetail, let latitude = placeDetail.latitude, let longitude = placeDetail.longitude {
print("Place Detail : \(latitude),\(longitude)")
} else {
print("No results")
}
}
Geocoding API
For live demo click LIVE DEMO
Get most accurate lat long combination for a given address
All mapping APIs that are used in mobile or web apps need some geo-position coordinates to refer to any given point on the map. Our Geocoding API converts real addresses into these geographic coordinates (latitude/longitude) to be placed on a map, be it for any street, area, postal code, POI or a house number etc.
Class used for geocode is MapplsAtlasGeocodeManager
. To create instance of MapplsAtlasGeocodeManager
initialize using your rest key, clientId, clientSecret , grantType or use shared instance of MapplsAtlasGeocodeManager
after setting key values MapplsRestKey
, MapplsAtlasClientId
, MapplsAtlasClientSecret
, MapplsAtlasGrantType
in your application’s Info.plist
file.
To perform geocode use getGeocodeResults
method of instance of MapplsAtlasGeocodeManager
class which accepts an instance of MapplsAtlasGeocodeOptions
class. To create instance of MapplsAtlasGeocodeOptions
, pass any address as query parameters to geocode.
Request Parameters
query
: The address of a location (e.g. 237 Okhla Phase-III).
Additionally you can also set some other parameters in object of MapplsAtlasGeocodeOptions
to get some specific results. Which are:
maximumResultCount
: The number of results which needs to be return in response.
Response Parameters
In response of geocode
search either you will receive an error or an array of MapplsGeocodedPlacemark
. Yo will find below useful properties in suggestion object :
houseNumber
: The house number of the location.houseName
: The name of the location.poi
: The name of the POI if the location is a place of interest (POI).street
: The name of the street of the location.subSubLocality
: The name of the sub-sub-locality where the location exists.subLocality
: The name of the sub-locality where the location exists.locality
: The name of the locality where the location exists.village
: The name of the village if the location exists in a village.district
: The name of the district in which the location exists.subDistrict
: The name of the sub-district in which the location exists.city
: The name of the city in which the location exists.state
: The name of the state in which the location exists.pincode
: The pin code of the location area.latitude
: The latitude of the location.longitude
: The longitude of the location.formattedAddress
: The complete human readable address string that is usually the complete postal address of the result.mapplsPin
: The Mappls Pin assigned for a place in map database. A Mappls Pin is the digital identity for an address or business to identify its unique location. For more information on Mappls Pin, click here.geocodeLevel
: It defines depth level of search for geocode.
Code Samples
Objective C
MapplsAtlasGeocodeManager * atlasGeocodeManager = [MapplsAtlasGeocodeManager sharedManager];
// or
MapplsAtlasGeocodeManager * atlasGeocodeManager = [[MapplsAtlasGeocodeManager alloc] initWithRestKey:MapplsAccountManager.restAPIKey clientId:MapplsAccountManager.atlasClientId clientSecret:MapplsAccountManager.atlasClientSecret grantType:MapplsAccountManager.atlasGrantType];
MapplsAtlasGeocodeOptions *atlasGeocodeOptions = [[MapplsAtlasGeocodeOptions alloc] initWithQuery: @"237 Mappls" withRegion:MapplsRegionTypeIndia];
[atlasGeocodeManager getGeocodeResultsWithOptions:atlasGeocodeOptions completionHandler:^(MapplsAtlasGeocodeAPIResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if (response!= nil && response.placemarks.count > 0) {
NSLog(@"Forward Geocode %@%@", response.placemarks[0].latitude, response.placemarks[0].longitude);
} else {
NSLog(@"No results");
}
}];
Swift
let atlasGeocodeManager = MapplsAtlasGeocodeManager.shared
// or
let atlasGeocodeManager = MapplsAtlasGeocodeManager(restKey: MapplsAccountManager.restAPIKey(), clientId: MapplsAccountManager.atlasClientId(), clientSecret: MapplsAccountManager.atlasClientSecret(), grantType: MapplsAccountManager.atlasGrantType())
let atlasGeocodeOptions = MapplsAtlasGeocodeOptions(query: "237 Mappls", withRegion: .india)
atlasGeocodeManager.getGeocodeResults(atlasGeocodeOptions) { (response, error) in
if let error = error {
NSLog("%@", error)
} else if let result = response, let placemarks = result.placemarks, placemarks.count > 0 {
print("Atlas Geocode: \(placemarks[0].latitude),\(placemarks[0].longitude)")
} else {
print("No results")
}
}
For more details visit our api reference documentation.
Routing API
For live demo click LIVE DEMO
Get optimal & alternate routes between various locations with or without considering live traffic
Routing and displaying driving directions on map, including instructions for navigation, distance to destination, traffic etc. are few of the most important parts of developing a map based application. This REST API calculates driving routes between specified locations including via points based on route type(optimal or shortest) and includes delays for traffic congestion.
Use Directions
to get route between locations. You can use it either by creating object using your rest key or use shared instance of Directions
class by setting rest key in the MapplsRestKey
key of your application’s Info.plist
file.
Swift
let directions = Directions.shared
Objective-C
MapplsDirections *directions = [MapplsDirections sharedDirections];
To perform this operation use object of RouteOptions
class as request to pass source location and destination locations and other parameters.
Request Parameters
To use Route with traffic based ETA feature, to get duration inclusive of traffic for a distance between locations use parameter resourceIdentifier as described below:
resourceIdentifier:
This property is type of enumMapplsDirectionsResourceIdentifier
with acceptable valuesrouteAdv
,routeETA
androuteTraffic
. The default value of this property isrouteAdv
.
To choose Travelling Mode use parameter profileIdentifier as described below:
profileIdentifier:
This property is type of enumMapplsDirectionsProfileIdentifier
with acceptable valuesdriving
,biking
,walking
andtrucking
. The default value of this property isdriving
.
Additionally you can set some more parameters on instance of RouteOptions
to get filtered/specific results as :
routeType
: It is type of enumMapplsRouteType
which can accept valuesquickest
,shortest
,none
. By default its value isnone
.region
: It is type of enumMapplsRegionType
. It is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal.
Note: If you are using Routing with traffic routeType
and region
values are not considered. Traffic is only available in India and only optimal route calculation is allowed with traffic.
Steps to get directions
- To get directions create an array of
Waypoint
class, add two objects ofWaypoint
class to this array to get route path. For origin position also set heading of instance ofWaypoint
class. - Next create an instance of
RouteOptions
class by passing waypoints created in previous step.
let options = RouteOptions(waypoints: [Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.551078, longitude: 77.268968), name: "Mappls"), Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.565065, longitude: 77.234193), name: "Moolchand")])
- Use
Directions
singleton class fromDirections
framework to get available routes. - You can plot polylines on map for available routes by using Map framework.
Directions Using Mappls Pins
An object of Waypoint can be created using coordinate as well as Mappls Pin (unique identifier of place).
Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.551078, longitude: 77.268968), name: "Mappls")
or
Waypoint(mapplsPin: "MMI000", name: "Mappls")
Code Samples
Swift
let waypoints = [
Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.551078, longitude: 77.268968), name: "Mappls"),
Waypoint(coordinate: CLLocationCoordinate2D(latitude: 28.565065, longitude: 77.234193), name: "Moolchand"),
]
let options = RouteOptions(waypoints: waypoints, resourceIdentifier: .routeAdv, profileIdentifier: .driving)
options.includesSteps = true
let task = Directions.calculate(options) { (waypoints, routes, error) in
guard error == nil else {
print("Error calculating directions: \(error!)")
return
}
if let route = routes?.first, let leg = route.legs.first {
print("Route via \(leg):")
let distanceFormatter = LengthFormatter()
let formattedDistance = distanceFormatter.string(fromMeters: route.distance)
let travelTimeFormatter = DateComponentsFormatter()
travelTimeFormatter.unitsStyle = .short
let formattedTravelTime = travelTimeFormatter.string(from: route.expectedTravelTime)
print("Distance: \(formattedDistance); ETA: \(formattedTravelTime!)")
for step in leg.steps {
print("\(step.instructions)")
let formattedDistance = distanceFormatter.string(fromMeters: step.distance)
print("— \(formattedDistance) —")
}
}
}
Objective-C
NSArray<MapplsWaypoint *> *waypoints = @[
[[MapplsWaypoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(28.551078, 77.268968) coordinateAccuracy:-1 name:@"Mappls"],
[[MapplsWaypoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(28.565065, 77.234193) coordinateAccuracy:-1 name:@"Moolchand"],
];
MapplsRouteOptions *options = [[MapplsRouteOptions alloc] initWithWaypoints:waypoints
resourceIdentifier:MapplsDirectionsResourceIdentifierRouteETA
profileIdentifier:MapplsDirectionsProfileIdentifierDriving];
options.includesSteps = YES;
NSURLSessionDataTask *task = [directions calculateDirectionsWithOptions:options
completionHandler:^(NSArray<MapplsWaypoint *> * _Nullable waypoints,
NSArray<MapplsRoute *> * _Nullable routes,
NSError * _Nullable error) {
if (error) {
NSLog(@"Error calculating directions: %@", error);
return;
}
MapplsRoute *route = routes.firstObject;
MapplsRouteLeg *leg = route.legs.firstObject;
if (leg) {
NSLog(@"Route via %@:", leg);
NSLengthFormatter *distanceFormatter = [[NSLengthFormatter alloc] init];
NSString *formattedDistance = [distanceFormatter stringFromMeters:leg.distance];
NSDateComponentsFormatter *travelTimeFormatter = [[NSDateComponentsFormatter alloc] init];
travelTimeFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
NSString *formattedTravelTime = [travelTimeFormatter stringFromTimeInterval:route.expectedTravelTime];
NSLog(@"Distance: %@; ETA: %@", formattedDistance, formattedTravelTime);
for (MapplsRouteStep *step in leg.steps) {
NSLog(@"%@", step.instructions);
NSString *formattedDistance = [distanceFormatter stringFromMeters:step.distance];
NSLog(@"— %@ —", formattedDistance);
}
}
}];
Usage with other Mappls Libraries
Drawing Route on mappls's Map
Refer the code below to draw the route on a map:
// main.swift
if route.coordinateCount > 0 {
// Convert the route’s coordinates into a polyline.
var routeCoordinates = route.coordinates!
let routeLine = MGLPolyline(coordinates: &routeCoordinates, count: route.coordinateCount)
// Add the polyline to the map and fit the viewport to the polyline.
mapView.addAnnotation(routeLine)
mapView.setVisibleCoordinates(&routeCoordinates, count: route.coordinateCount, edgePadding: .zero, animated: true)
}
// main.m
if (route.coordinateCount) {
// Convert the route’s coordinates into a polyline.
CLLocationCoordinate2D *routeCoordinates = malloc(route.coordinateCount * sizeof(CLLocationCoordinate2D));
[route getCoordinates:routeCoordinates];
MGLPolyline *routeLine = [MGLPolyline polylineWithCoordinates:routeCoordinates count:route.coordinateCount];
// Add the polyline to the map and fit the viewport to the polyline.
[mapView addAnnotation:routeLine];
[mapView setVisibleCoordinates:routeCoordinates count:route.coordinateCount edgePadding:UIEdgeInsetsZero animated:YES];
// Make sure to free this array to avoid leaking memory.
free(routeCoordinates);
}
Driving Distance Time Matrix API
For live demo click LIVE DEMO
Get driving distance & time from a point to multiple destination
Adding driving distance matrix API would help to add predicted travel time & duration from a given origin point to a number of points. The Driving Distance Matrix API provides driving distance and estimated time to go from a start point to multiple destination points, based on recommended routes from Mappls Map and traffic flow conditions.
Class used for driving distance is MapplsDrivingDistanceMatrixManager
. Create a MapplsDrivingDistanceMatrixManager
object using your rest key or alternatively, you can place your rest key in the MapplsRestKey
key of your application’s Info.plist
file, then use the shared instance of MapplsDrivingDistanceMatrixManager
class.
To perform this operation use MapplsDrivingDistanceMatrixOptions
class to pass center location and points parameters.
To use API Distance Matrix with traffic to get duration inclusive of traffic for a distance between locations use parameter resourceIdentifier
as described below:
resourceIdentifier:
This property is type of enumMapplsDistanceMatrixResourceIdentifier
with acceptable valuesdefault
,eta
andtraffic
. The default value of this property isdefault
.
To choose Travelling Mode use parameter profileIdentifier as described below:
profileIdentifier:
This property is type of enumMapplsDirectionsProfileIdentifier
with acceptable valuesdriving
,biking
,walking
andtrucking
. The default value of this property isdriving
.
Request Parameters
Additionally you can pass some other parameters to get filtered/specific results. Which are as :
- routeType: It is type of enum
DistanceRouteType
. - region: It is type of enum
MapplsRegionType
. It is used to validate and get result for different countries. Currently five countries are supported including India which are Sri Lanka, India, Bhutan, Bangladesh, Nepal. - sourceIndexes: It is an array of int which specifie index of the source locations
- destinationIndexes: It is an array of int which specifie index of the destinations locations.
Note: If you are using Distance Matrix with traffic routeType
and region
values are not considered. Traffic is only available in India and only optimal route calculation is allowed with traffic.
Response Parameters
In response either you will receive an error or an object of MapplsDrivingDistanceMatrixResponse
where structure of object is as described below:
responseCode
: API status code.version
: API’s version informationresults
: Array of results, each consisting of the following parameterscode
: if the request was successful, code is “ok”.durations
: duration in seconds for source to secondary locations in order as passed.distances
: distance in meters for source to secondary locations in order as passed.
Code Samples
Objective C
MapplsDrivingDistanceMatrixManager *distanceMatrixManager = [MapplsDrivingDistanceMatrixManager sharedManager];
MapplsDrivingDistanceMatrixOptions *distanceMatrixOptions = [[MapplsDrivingDistanceMatrixOptions alloc] initWithCenter:[[CLLocation alloc] initWithLatitude: 28.543014 longitude:77.242342] points:[NSArray arrayWithObjects: [[CLLocation alloc] initWithLatitude:28.520638 longitude:77.201959], [[CLLocation alloc] initWithLatitude:28.511810 longitude: 77.252773], nil] withRegion:MapplsRegionTypeIndia];
[distanceMatrixManager getResultWithOptions:distanceMatrixOptions completionHandler:^(MapplsDrivingDistanceMatrixResponse * _Nullable result, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
} else if (result != nil && result.results != nil) {
NSArray<NSNumber *> *durations = result.results.durations.firstObject;
NSArray<NSNumber *> *distances = result.results.distances.firstObject;
NSUInteger pointCount = [distanceMatrixOptions points].count;
for (NSUInteger i = 0; i < pointCount; i++) {
if (i < durations.count && i < distances.count) {
NSLog(@"Driving Distance Matrix ETA %lu duration: %@, distance: %@", (unsigned long)i, durations[i], distances[i]);
}
}
} else {
NSLog(@"No results");
}
}];
Swift
let distanceMatrixManager = MapplsDrivingDistanceMatrixManager.shared
let distanceMatrixOptions = MapplsDrivingDistanceMatrixOptions(center: CLLocation(latitude: 28.543014, longitude: 77.242342), points: [CLLocation(latitude: 28.520638, longitude: 77.201959), CLLocation(latitude: 28.511810, longitude: 77.252773)])
distanceMatrixOptions.profileIdentifier = .driving
distanceMatrixOptions.resourceIdentifier = .eta
distanceMatrixManager.getResult(distanceMatrixOptions) { (result, error) in
if let error = error {
NSLog("%@", error)
} else if let result = result, let results = result.results, let durations = results.durations?[0], let distances = results.distances?[0] {
let pointCount = distanceMatrixOptions.points?.count ?? -1
for i in 0..<pointCount {
if i < durations.count && i < distances.count {
print("Driving Distance Matrix ETA \(i): duration: \(durations[i]) distance: \(distances[i])")
}
}
} else {
print("No results")
}
}
Distance Using Mappls Pin
Code snipet for getting distance between different locations using Mappls Pin is below.
let distanceMatrixManager = MapplsDrivingDistanceMatrixManager.shared
et distanceMatrixOptions = MapplsDrivingDistanceMatrixOptions(locations: ["JIHGS1", "17ZUL7", "77.242342,28.543014", "17ZUL7"], withRegion: .india)
distanceMatrixOptions.profileIdentifier = .driving
if isETA {
distanceMatrixOptions.resourceIdentifier = .eta
}
distanceMatrixOptions.sourceIndexes = [0,1]
distanceMatrixOptions.destinationIndexes = [2,3]
distanceMatrixManager.getResult(distanceMatrixOptions) { (result, error) in
if let error = error {
NSLog("%@", error)
} else if let result = result, let results = result.results, let durations = results.durationsAPI?[0], let distances = results.distancesAPI?[0] {
let pointCount = distanceMatrixOptions.locations?.count ?? -1
for i in 0..<pointCount {
if i < durations.count && i < distances.count {
let duration = durations[i].intValue
let distance = distances[i].intValue
print("Driving Distance Matrix\(isETA ? " ETA" : "") \(i): duration: \(duration) distance: \(distance)")
}
} else {
print("No results")
}
}
}
For more details visit our api reference documentation.
POI Along The Route API
With POI Along the Route API user will be able to get the details of POIs of a particular category along his set route. The main focus of this API is to provide convenience to the user and help him in locating the place of his interest on his set route.
Class used to get list of POI along a route is MapplsPOIAlongTheRouteManager
. Create an object of this class using Mappls's API Keys or alternatively use shared instance of MapplsPOIAlongTheRouteManager
class.
Note: To use shared SDK must be initilized by setting Mappls's API Acesss Keys using class MapplsAccountManager
of framework MapplsAPIKit
. For more information please see here.
Request Parameters
MapplsPOIAlongTheRouteOptions
is request class which will be used to pass all required and optional parameters. So it will be require to create an instance of MapplsPOIAlongTheRouteOptions
and pass that instance to getPOIsAlongTheRoute
function of MapplsPOIAlongTheRouteManager
.
Mandatory Parameters:
- path: This parameter takes the encoded route along which POIs to be searched. It is of type
String
. - category: The POI category code to be searched. Only one category input supported. It is of type
String
.
Optional Parameters:
Additionally you can pass some other parameters to get filtered/specific results. Which are as :-
- sort: It is of type
Bool
. Gets the sorted POIs along route. - geometries: It is of enum type
MapplsPolylineGeometryType
, default value ispolyline5
. Values of enum specifies type of geometry encoding. - buffer: It is of type
Int
. Buffer of the road. - page: It is of type
Int
. Used for pagination. By default, a request returns maximum 10 results and to get the next 10 or so on pass the page value accordingly. Default is 1.
Response Parameters:
In callback of getPOIsAlongTheRoute
function it will either return an error object of type 'NSError' or an array of type MapplsPOISuggestion
. Below is list of parameters of MapplsPOISuggestion
:
- distance: distance of the POI.
- mapplsPin: Mappls Pin of the POI
- poi: Name of the POI
- subSubLocality: Subsublocality of the POI
- subLocality: Sublocality of the POI
- locality: Locality of the POI
- city: City of the POI
- subDistrict: Sub district of the POI
- district: District of the POI
- state: State of the POI
- popularName: Popular name of the POI
- address: Address of the POI
- telephoneNumber: Telephone number of the POI
- email: Email of the POI
- website: Website of the POI
- latitude: Latitude of the POI
- latitudeObjC:
latitude
only while coding in Objective-C. - longitude: Longitude of the POI
- longitudeObjC:
longitude
only while coding in Objective-C. - entryLatitude: Entry latitude of the POI
- entryLatitudeObjC:
entryLatitude
only while coding in - entryLongitude: Entry longitude of the POI
- entryLongitudeObjC:
entryLongitude
only while coding in Objective-C. - brandCode: Brand id of the POI
Swift
let poiAlongTheRouteManager = MapplsPOIAlongTheRouteManager.shared
let routePath = "mfvmDcalvMB?B?@EB}@lABzABrBDAaAFoDFuCFuC@{@@m@DoAFu@D_@VmAFWHSHKBCFCbA]n@S`@IX?^BdAL|ANtCV~ANXBfBDfBBl@Bp@BrA@Pa@FKHMf@@`CHXDLBJFHJHRbD@`D@Z?h@@f@@h@@bAB^@jDDlBB~@BT@N?dDDV?x@Bt@@dCFdCFzB@nD?N?|BEzBEzBE`@AJ?lCOxCMfAClCGnCIlCIlCIhDKfDIhDIzCK|AG|AEbBG`A@d@FVD^FjARlBVn@D`AD|@Fn@DnCZnCZtBTH@J?V@`A@lC@nC@lCB`AGNCTCPEl@SRI|@a@~BqAb@OZGt@E|BEl@AxA?|@?pA@T?V@bCB`AJNBn@L^NpAl@t@`@d@V~BlA`CnA~BnA`A`@VJd@NXF~@JN@xBBL?hA?x@Ar@?x@A@?vCAvCAvCAxCAj@F`@Fd@Nf@RrAn@|@b@dBz@fBz@nBfAJF~Ax@`CfAXLRHp@XtCpAtCrAf@V|@Rf@Px@TxAZF`BL`BLZEPERGNKPQR_@BaBPeEHeAXo@NcDLaDNaDNaDAkB?kAKqDIoD_@mAI{BI{BGgBIgBGiBCm@ASAi@Cu@Cc@Ag@Aa@GgBGgBGkBAu@IeCAUJARARA~@GB?f@C|AK`BIbBIt@IPCPCZO`@[FKLOR]Vk@Pi@DUL{@D[P}CP{C@i@@a@Ae@EiBCiBAyC?_ACaB?QAeBAgB?WB_@BSDSDOTu@dA{Cr@sBRi@JU^q@j@cATYZ_@TUbBsAHIhA}@jA_AlAaA`Ay@bAy@d@c@pAgAv@q@`AcA^_@tAoAVSVQLGdAg@f@Yz@e@W_@KSWIoAuCmAwCLMBCDCNE@AJ?H@F@v@fBGNGb@WYfAcALI@C@CBADCD@JBDBBBBD@D?DDLBFJNFDHDF@J@|CKbCItAEHCHA@EBEDCDABAF?D@DB@BDH@D?JADL@l@?j@BbAGGcAGiACc@Cm@C["
let poiAlongTheRouteOptions = MapplsPOIAlongTheRouteOptions(path: routePath, category: "FODCOF")
poiAlongTheRouteOptions.buffer = 300
poiAlongTheRouteManager.getPOIsAlongTheRoute(poiAlongTheRouteOptions) { (suggestions, error) in
if let error = error {
} else if let suggestions = suggestions {
for suggestion in suggestions {
print("POI Along \(suggestion.latitude) \(suggestion.longitude)")
}
}
}
Objective-C
MapplsPOIAlongTheRouteManager * poiAlongTheRouteManager = [MapplsPOIAlongTheRouteManager sharedManager];
NSString *routePath = @"mfvmDcalvMB?B?@EB}@lABzABrBDAaAFoDFuCFuC@{@@m@DoAFu@D_@VmAFWHSHKBCFCbA]n@S`@IX?^BdAL|ANtCV~ANXBfBDfBBl@Bp@BrA@Pa@FKHMf@@`CHXDLBJFHJHRbD@`D@Z?h@@f@@h@@bAB^@jDDlBB~@BT@N?dDDV?x@Bt@@dCFdCFzB@nD?N?|BEzBEzBE`@AJ?lCOxCMfAClCGnCIlCIlCIhDKfDIhDIzCK|AG|AEbBG`A@d@FVD^FjARlBVn@D`AD|@Fn@DnCZnCZtBTH@J?V@`A@lC@nC@lCB`AGNCTCPEl@SRI|@a@~BqAb@OZGt@E|BEl@AxA?|@?pA@T?V@bCB`AJNBn@L^NpAl@t@`@d@V~BlA`CnA~BnA`A`@VJd@NXF~@JN@xBBL?hA?x@Ar@?x@A@?vCAvCAvCAxCAj@F`@Fd@Nf@RrAn@|@b@dBz@fBz@nBfAJF~Ax@`CfAXLRHp@XtCpAtCrAf@V|@Rf@Px@TxAZF`BL`BLZEPERGNKPQR_@BaBPeEHeAXo@NcDLaDNaDNaDAkB?kAKqDIoD_@mAI{BI{BGgBIgBGiBCm@ASAi@Cu@Cc@Ag@Aa@GgBGgBGkBAu@IeCAUJARARA~@GB?f@C|AK`BIbBIt@IPCPCZO`@[FKLOR]Vk@Pi@DUL{@D[P}CP{C@i@@a@Ae@EiBCiBAyC?_ACaB?QAeBAgB?WB_@BSDSDOTu@dA{Cr@sBRi@JU^q@j@cATYZ_@TUbBsAHIhA}@jA_AlAaA`Ay@bAy@d@c@pAgAv@q@`AcA^_@tAoAVSVQLGdAg@f@Yz@e@W_@KSWIoAuCmAwCLMBCDCNE@AJ?H@F@v@fBGNGb@WYfAcALI@C@CBADCD@JBDBBBBD@D?DDLBFJNFDHDF@J@|CKbCItAEHCHA@EBEDCDABAF?D@DB@BDH@D?JADL@l@?j@BbAGGcAGiACc@Cm@C[";
MapplsPOIAlongTheRouteOptions * poiAlongTheRouteOptions = [[MapplsPOIAlongTheRouteOptions alloc] initWithPath:routePath category:@"FODCOF"];
poiAlongTheRouteOptions.buffer = 300;
[poiAlongTheRouteManager getPOIsAlongTheRoutekWithOptions:poiAlongTheRouteOptions completionHandler:^(NSArray<MapplsPOISuggestion *> * _Nullable suggestions, NSError * _Nullable error) {
if (error) {
} else if (suggestions) {
for (MapplsPOISuggestion *suggestion in suggestions) {
NSLog(@"POI Along %@%@ %@ %@", suggestion.latitudeObjC, suggestion.longitudeObjC, suggestion.mapplsPin, suggestion.distanceObjC);
}
}
}];
For more details visit our api reference documentation
Nearby Reports API
Nearby Reports enables the user to get required reports related to traffic, safety, community issues etc on the basis of input bound.
Class used to get list of Nearby Reports API is MapplsNearbyReportManager
. Create an object of this class using Mappls's API Keys or alternatively use shared instance of MapmyIndidiaNearbyReportManager
class.
Note: To use shared SDK must be initilized by setting Mappls's API Acesss Keys using class MapplsAccountManager
of framework MaplsAPIKit
. For more information please see here.
Request Parameters
MapplsNearbyReportOptions
is request class which will be used to pass all required and optional parameters. So it will be require to create an instance of MapplsNearbyReportOptions
and pass that instance to getNearbyReportResult
function of MapmyIndidiaNearbyReportManager
.
Mandatory Parameters:
- bound: This parameter takes bound. It is of type
MapplsRectangularRegion
which is s a rectangular bounding box for a geographic region. whic contains following parameters a. bottomRight :- Coordinate at the bottomRight corner which is of typeCLLocationCoordinate2D
b. topLeft:- Coordinate at the northeast corner which is of typeCLLocationCoordinate2D
Response Parameters:
In callback of getPOIsAlongTheRoute
function it will either return an error object of type 'NSError' or an array of type MapplsNearbyReportResponse
. Below is list of parameters of MapplsNearbyReportResponse
:
id
(String): Id of the report.latitude
(Double): Latitude of the report.longitude
(Double): Longitude of the report.category
(String): Report categorycreatedOn
(Int): Timestamp when event created
Swift
let nearbyReportManager = MapplsNearbyReportManager.shared
let topleft = CLLocationCoordinate2D(latitude: 28.0, longitude: 78.32)
let bottomRight = CLLocationCoordinate2D(latitude: 34.0, longitude: 78.32)
let bound = MapplsRectangularRegion(topLeft: topleft, bottomRight: bottomRight)
let option = MapplsNearbyReportOptions(bound: bound)
nearbyReportManager.getNearbyReportResult(option) { (response, error) in
if let error = error {
print("error: \(error.localizedDescription)")
} else {
if let res: MapplsNearbyReportResponse = response, let totalItem = res.pagination?.totalItems {
if let reports = res.reports {
for i in reports {
if let lat = i.latitude, let long = i.longitude {
let coordinate = CLLocationCoordinate2D(latitude: lat, longitude: long)
print("Reported Coordinate: \(coordinate)")
}
}
}
print("Total item : \(totalItem)")
}
}
}
Current Weather Condition API
API enables the developer to access current weather condition around whole India. This also enable developer to fetch current
- Air quality index
- Temperature
- Humidity
- Wind
- Visibility
Class used to get list of Current Weather Condition API is MapplsWeatherManager
. Create an object of this class using Mappls's API Keys or alternatively use shared instance of MapplsWeatherManager
class.
Note: To use shared SDK must be initilized by setting Mappls's API Acesss Keys using class MapplsAccountManager
of framework MaplsAPIKit
. For more information please see here.
Request Parameters
MapplsWeatherRequestOptions
is request class which will be used to pass all required and optional parameters. So it will be require to create an instance of MapplsWeatherRequestOptions
and pass that instance to getResults
function of MapplsWeatherManager
.
Mandatory Parameters:
location
: It is of typeCLLLocation
which takesLatitude
andlongitude
of place
Optional Parameter
tempUnit (String)
: Unit of temperature. Below are the available value:- "C" celcius(°C)
- "F" farenheit (F)
theme (MapplsIconTheme)
: This parameter is used to define the theme of icon. Below are the available value:- MapplsIconThemeDark
- MapplsIconThemeLight
size (MapplsWeatherIconSize )
: This parameter is used to define the size of icon. Below are the available value:- MapplsWeatherIconSize36PX (Default)
- MapplsWeatherIconSize24PX
unitType (MapplsWeatherForcastUnitType)
: This parameter defines the unit type on the basis of which weather forecast information is sought for. Below are the available value:- MapplsWeatherForcastUnitTypeDay
- MapplsWeatherForcastUnitTypeHour
unit (string)
: This parameter is the value for which forecast information is sought for. Valid values are:- For Days
1
5
10
- For Hours
1
24
- For Days
Response Parameters:
In callback of getResults
function it will either return an error object of type NSError
or an array of type MapplsWeatherResponse
. Below is list of parameters of MapplsWeatherResponse
:
Response parameters
data
(MapplsWeatherData
)
MapplsWeatherData result parameters:
temperature
(MapplsWeatherTemperature
)MapplsWeatherTemperature result parameters:
value
(NSNumber
): Temperature value.For eg:31.3unit
(String
): Temperature unit.For eg:"°C"
weatherCondition
(MapplsWeatherCondition
): Weather condition infoMapplsWeatherCondition result parameters:
weatherId
(NSNumber
): Id of Weather condition. For eg:5weatherText
(String
): Weather condition info text.For eg:"Hazy sunshine"weatherDescription
(String
): Description of weather For eg: "Total cloud cover between 20%-60%"weatherIcon
(String
): Weather condition icon url.realFeelWeatherText
(String
):Description of weather For eg:"Feels Like 41.0 °C"
airQuality
(MapplsAirQuality
): Air Quality infoAirQuality result parameters:
airQualityIndex
(NSNumber
): Give the value of air quality index. For eg:104airQualityIndexText
(String
): Description for AQI given. For eg: "Unhealthy for Sensitive Groups"airQualityIndexUnit
(String
): Gives the values of airquality index unit. For eg: "PM2.5"
humidity
(MapplsHumidity
): MapplsHumidity infoMapplsHumidity result parameters:
relHumidity
(NSNumber
): Provides the value for humidity. For Eg: 65indoorRelHumidity
(NSNumber
): Provide value for indoor relative humidity . For eg: 65
wind
(MapplsWind
): Mappls InfoMappls result parameters:
windSpeed
(NSNumber
):For Eg:12.8windSpeedUnit
(String
):For Eg: "KM/H"windAngle
(NSNumber
):For Eg: 338windAngleUnit
(String
): For Eg: "NNW"
visibility
(MapplsVisibility
): MapplsVisibility InfoMapplsVisibility result parameters:
value
(NSNumber
): Visibilty value. For eg: 2unit
(String
): Unit of Visibilty value. For eg: "KM"
forecastData
: This feature is available for your solutions to get forecast details. The API is able to populate current weather condition andforecast
of1
,5
&10
days (depending on input)or hours based forecast for1
hr and24
hrs.MapplsForecastData result parameters:
hour
(String
): Value Returned when request is made for hours. For eg: "26/09/2022 18:00",date
(String
): Value Returned when request is made for multiple day/days. For eg: "28/09/2022",day
(String
): Represents day name when request is made for multiple day/days. For eg: "Wednesday".temperature
(MapplsWeatherTemperature
):minTemperature
(NSNumber
): Minimum temperature value for the day/night.For eg:31.3minTemperatureUnit
(String
): Minimum Temperature Unit. For eg:"°C"maxTemperature
(NSNumber
): Maximum Temperature value for the day/night.For eg:31.3maxTemperatureUnit
(String
): Maximum Temperature Unit. For eg:"°C"
weatherCondition
(MapplsWeatherCondition
)weatherIdDay
(NSNumber
): Shows the ID of the day For Eg: 1weatherTextDay
(String
): Shows the forcast description for the day For Eg: "Sunny"weatherIconDay
(String
): Shows the forcast icon for day For Eg: "1.png"weatherIdNight
(NSNumber
): Shows the ID of the night For Eg: 33weatherTextNight
(String
): Shows the forcast description for the night For Eg: "Clear"weatherIconNight
(String
): Shows the forcast icon for the night For Eg: "33.png"
Swift
let location = CLLocation(latitude: 28.787, longitude: 77.7873)
let options = MapplsWeatherRequestOptions(location: location)
// for 5 day weather forcast
options.unitType = .day
options.unit = "5"
// for icon theme
options.theme = .light
MapplsWeatherManager.shared.getResults(options) { weatherResponse, error in
if let error = error {
print("error: \(error.localizedDescription)")
} else {
if let temp = weatherResponse?.data?.temperature?.temperature , let unit = weatherResponse?.data?.temperature?.temperatureUnit {
print("current temperature: \(temp) \(unit)")
}
if let forcast = weatherResponse?.data?.forecastData {
for forecastData in forcast {
if let day = forecastData.day, let date = forecastData.date {
print("day: \(forecastData.day) Date: \(date)")
}
}
}
}
}
Objective-c
MapplsWeatherManager * manager = [MapplsWeatherManager sharedManager];
CLLocation *location = [[CLLocation alloc] initWithLatitude:28.00 longitude:78.00];
MapplsWeatherRequestOptions *options = [[MapplsWeatherRequestOptions alloc] initWithLocation:location];
options.theme = MapplsIconThemeLight;
options.unitType = MapplsWeatherForcastUnitTypeHour;
options.unit = @"5";
[manager getResultsWithOptions:options completionHandler:^(MapplsWeatherResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil ) {
NSLog(@"error: %@", error.localizedDescription);
} else {}
NSLog(@"temperature %@", response.data.temperature.temperature);
NSLog(@"temperatureUnit %@", response.data.temperature.temperatureUnit);
for (MapplsForecastData* weatherForcast in response.data.forecastData){
NSLog(@"day %@", weatherForcast.day);
NSLog(@"date %@", weatherForcast.date);
}
}
}];
Congestion Delays
To get congestion delays for a route, a helper function getCongestionDelays
added in class of MapplsDirectionUtility.
getCongestionDelays
Parameters:
- route: An instance of 'Route'.
- fromLocation: Location coordinate from which congestion is to be calculate on a route. The coordinate should lie on line of coordinates of route.
- uptoDistane: Distance in meters, upto which congestion is to be calculate on a route
- minCongestionDelay: Minimum delay in minutes, greater than that only congestion will be returned. This value should be greated then or equal to 1.
Returns:
Will return an array of CongestionDelayInfo
which contains delay in seconds and center coordinate.
Swift
let congestionDelays = MapplsDirectionsUtility().getCongestionDelays(forRoute: route, fromLocation: currentLocation, uptoDistane: 50, minCongestionDelay: 5)