Map Config
This class gives the possibility to configure and customise the Map capabilities such as :
- Download location thumbnail preview
- Search for places
- Retrieve country code
- Get address from location
- Get Detailed address from location
By default, there is a multiple existing configuration for map provider such as :
- OpenStreetMap
- ArcGIS
You can customize this class by using a third party library like Google map location.
The following example gives an idea how to use and customise the map config :
Create a custom map config :
class CustomMapProvider extends MapProvider {
public String getSearchPlacesURL(Context context, String search)
{
return "<http://search_places_url>";
}
public String getLocationThumbnailUrl(Context context, String latitude, String
longitude, String markerColor,
boolean addMarker)
{
return "<http://location_thumbnail_url>";
}
public String handleParseGeoCoderCountryCode(String response)
{
String countryCode = <parse_GeoCoder_for_CountryCode_result>
return countryCode;
}
public List<PositionItem> handleParsePlaces(String jsonResult)
{
List<PositionItem> positionList = <parse_places_result_json>;
return positionList;
}
public void handleAddressFromLocation(Context context, double lat, double lng,
ISearchLocation listener)
{
// retrieve_address_from_given_location
}
public void handleDetailedAddressFromLocation(Context context, double lat, double lng,
ISearchLocation listener)
{
// retrieve_detailed_address_from_given_location
}
}
MapConfig customMapConfig =
new MapConfig
.Builder()
.mapProvider(new CustomMapProvider())
.build();
SDKEnvironment.initMapConfig(customMapConfig);
Content copied to clipboard
In order to use this class with the Google location &map capabilities, an existing configuration is done for you and can be used by following these steps :
- Add the swgooglemaplib aar file to your gradle file :
implementation files('libs/swgooglemaplib-rXXXX.aar')Content copied to clipboard - Add this snippet code to initialize the Map config using swgooglemaplib library :
MapConfig customMapConfig = new MapConfig .Builder() .mapProvider(new GoogleMapProvider()) .build(); SDKEnvironment.initMapConfig(customMapConfig);Content copied to clipboard
For the implementation :
MapProvider mapProvider = SDKEnvironment.getMapConfig();
if (mapProvider != null) {
// use mapProvider methods
}
Content copied to clipboard
MapProvider can offers a multiple operation such as :
- Search for places
mapProvider.searchForPlace(context, "<query>", new ISearchLocation() { public void onError(Object result, boolean isLibraryError) { } public void onComplete(Object response) { } });Content copied to clipboard - Construct the location thumbnail url
String locationThumbnailUrl = mapProvider.getLocationThumbnailUrl(context, String.valueOf(latitude), String.valueOf(longitude), "green", true);Content copied to clipboard - Download location thumbnail
mapProvider.downloadAttachmentLocation(context, latitude, longitude, "green", true, "thumbFilePath", new IDownloadLocation() { public void onDownloading() { } public void onComplete(String filePath) { } });Content copied to clipboard - Retrieve country code
mapProvider.getCountryCode(context, latitude, longitude, new ISearchLocation() { public void onError(Object result, boolean isLibraryError) { } public void onComplete(Object response) { } });Content copied to clipboard - Retrieve address from location
mapProvider.handleAddressFromLocation(context, latitude, longitude, new ISearchLocation() { public void onError(Object result, boolean isLibraryError) { } public void onComplete(Object response) { } });Content copied to clipboard - Retrieve detailed address from location
mapProvider.handleDetailedAddressFromLocation(context, latitude, longitude, new ISearchLocation() { public void onError(Object result, boolean isLibraryError) { } public void onComplete(Object response) { } });Content copied to clipboard - Parse places result
List<PositionItem> positionList = mapProvider.handleParsePlaces("<places_result>");Content copied to clipboard - Construct search for places url
String searchPlacesUrl = mapProvider.getSearchPlacesURL(context, "<search_key>");Content copied to clipboard