MapConfig

open class MapConfig

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);

    

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 :

  1. Add the swgooglemaplib aar file to your gradle file :
    
             implementation files('libs/swgooglemaplib-rXXXX.aar')
        
  2. Add this snippet code to initialize the Map config using swgooglemaplib library :
    
             MapConfig customMapConfig =
                 new MapConfig
                     .Builder()
                     .mapProvider(new GoogleMapProvider())
                     .build();
    
             SDKEnvironment.initMapConfig(customMapConfig);
        

For the implementation :


         MapProvider mapProvider = SDKEnvironment.getMapConfig();

         if (mapProvider != null) {
             // use mapProvider methods
         }
    

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)
                     {
    
                     }
                 });
             
  • Construct the location thumbnail url
    
                 String locationThumbnailUrl = mapProvider.getLocationThumbnailUrl(context, String.valueOf(latitude),
                                                                 String.valueOf(longitude), "green", true);
            
  • Download location thumbnail
    
                 mapProvider.downloadAttachmentLocation(context, latitude, longitude, "green", true, "thumbFilePath",
                     new IDownloadLocation() {
    
                         public void onDownloading()
                         {
    
                         }
    
                         public void onComplete(String filePath)
                         {
    
                         }
                 });
             
  • Retrieve country code
    
                 mapProvider.getCountryCode(context, latitude, longitude, new ISearchLocation() {
    
                     public void onError(Object result, boolean isLibraryError)
                     {
    
                     }
    
                     public void onComplete(Object response)
                     {
    
                     }
                 });
            
  • Retrieve address from location
    
                 mapProvider.handleAddressFromLocation(context, latitude, longitude, new ISearchLocation() {
    
                     public void onError(Object result, boolean isLibraryError)
                     {
    
                     }
    
                     public void onComplete(Object response)
                     {
    
                     }
                 });
             
  • Retrieve detailed address from location
    
                 mapProvider.handleDetailedAddressFromLocation(context, latitude, longitude, new ISearchLocation() {
    
                     public void onError(Object result, boolean isLibraryError)
                     {
    
                     }
    
                     public void onComplete(Object response)
                     {
    
                     }
                 });
             
  • Parse places result
    
                 List<PositionItem> positionList = mapProvider.handleParsePlaces("<places_result>");
             
  • Construct search for places url
    
                 String searchPlacesUrl = mapProvider.getSearchPlacesURL(context, "<search_key>");
             

See also

com.streamwide.smartms.lib.template.map.MapProvider
com.streamwide.smartms.lib.core.internal.geolocation.map.ArcGISMapProvider
com.streamwide.smartms.lib.core.internal.geolocation.map.OSMMapProvider

Types

Link copied to clipboard
open class Builder

Properties

Link copied to clipboard
val mapProvider: MapProvider