RemoteSearchService

Remote search service is built on the Internet (uniconnect) and AMap search service above services across the remote service of the machine. The service can be directly used AMap search services at a remote device (e.g. Geographic Encoding, inverse Geographic Encoding, query, administrative district planning POI search, POI search around, POIID POI search function, the relationship between father and son, bus line query, point query, bus station path planning function), in addition to the current path planning function API support Android and iOS, other functions only temporarily in Android SDK.

Basic concept

SearchServiceProxy (For Android) / IWDSSearchServiceProxy (For iOS)

As a proxy for the remote search service, the API is used to invoke the AMap search service, and the search results are sent to the remote device / response to the remote device (watch). It provides Geographic Encoding, inverse Geographic Encoding, query, administrative district planning POI keyword search, POI search, POIID search function, peripheral POI between father and son, bus line query, bus site inquiries, path planning and other functions.

RemoteSearchService

The remote search service runs on the watch end and is used to send a request to the search service agent and respond to its search results.

RemoteSearchServiceManager

The remote search service manager, it is the interface provided by the remote search service.

Remote[XXX]Search

In a remote search object, the user can set the callback of the remote search service.

RemoteRouteSearch

    /**
     * 设置公交路线查询参数
     * 
     * @param query
     *            公交路线查询参数
     */
    public void setBusRouteQuery(RemoteBusRouteQuery query);

    /**
     * 设置驾车路线查询参数
     * 
     * @param query
     *            驾车路线查询参数
     */
    public void setDriveRouteQuery(RemoteDriveRouteQuery query);

    /**
     * 设置步行路线查询参数
     * 
     * @param query
     *            步行路线查询参数
     */
    public void setWalkRouteQuery(RemoteWalkRouteQuery query);

    /**
     * 设置骑行路线查询参数
     * 
     * @return 骑行路线查询参数
     */
    public void setRideRouteQuery(RemoteRideRouteQuery rideRouteQuery);

    /**
     * 设置路径搜索结果监听接口
     * 
     * @param listener
     *            路径搜索结果监听接口
     */
    public void setRouteSearchListener(RemoteRouteSearchListener listener);

RemoteGeocodeSearch

    /**
     * 设置地理编码查询的关键字和查询城市
     * 
     * @param query
     *            地理编码查询的关键字和查询城市
     */
    public void setGeocodeQuery(RemoteGeocodeQuery query);

    /**
     * 设置逆地理编码查询的地理坐标点、查询范围、坐标类型
     * 
     * @param query
     *            逆地理编码查询的地理坐标点、查询范围、坐标类型
     */
    public void setRegeocodeQuery(RemoteRegeocodeQuery query);

    /**
     * 设置监听接口
     * 
     * @param listener
     *            监听接口
     */
    public void setGeocodeSearchListener(RemoteGeocodeSearchListener listener);

The following search interface and RemoteGeocodeSearch similar

RemoteDistrictSearch;

RemotePoiSearch(POI - Point Of Interest);

RemoteInputtips;

RemoteBusLineSearch;

RemoteBusStationSearch.

How to use

At present, the function of path planning is supported by the mobile terminal, and then the route result is sent to the watch:

ANDROID CODE:

    // 获取搜索服务代理对象,initialize(context)和start()在Application.onCreate()中已调用,
    // 因此在使用时无需再次调用,重复调用无效
    SearchServiceProxy mProxy = SearchServiceProxy.getInstance();

    // 设置高德开放平台获取的ApiKey
    // ApiKey获取方法请参见:
    // http://lbs.amap.com/api/android-sdk/guide/create-project/get-key
    // 默认使用的ApiKey由深圳君正为WatchManager应用申请,
    // 如需开发自己的手机客户端,请设置自己的ApiKey
    mProxy.setApiKey(yourAppKey);


    // 路径规划的两种方法:
    // 方法一:直接使用高德高德API提供的路径规划接口,使用方法请参见:
    // http://lbs.amap.com/api/android-sdk/guide/route-plan/drive

    // 方法二:使用SearchServiceProxy中封装的Api接口,用法如下:

    /**
     * 设置路径规划监听
     * @param listener 路径规划监听,通过回调方法可获取路径规划路线的结果
     */
    public void setRouteSearchListener(OnRouteSearchListener listener);

    /**
     * 路径规划异步方法,通过OnRouteSearchListener的回调方法获取路线结果,
     * 公交和驾车路径规划建议使用方法一实现
     * @param queryType 路径规划的类型
     *        <ul>
     *            <li>{@link #QUERY_TYPE_BUS_ROUTE_SEARCH QUERY_TYPE_BUS_ROUTE_SEARCH-公交}</li>
     *            <li>{@link #QUERY_TYPE_DRIVE_ROUTE_SEARCH QUERY_TYPE_DRIVE_ROUTE_SEARCH-驾车}</li>
     *            <li>{@link #QUERY_TYPE_RIDE_ROUTE_SEARCH QUERY_TYPE_RIDE_ROUTE_SEARCH-骑行}</li>
     *            <li>{@link #QUERY_TYPE_WALK_ROUTE_SEARCH QUERY_TYPE_RIDE_ROUTE_SEARCH=步行}</li>
     *        <ul/>
     * @param fromAndTo 路线的起点和终点信息
     * @param mode 路径规划的模式 {@link com.amap.api.services.route.RouteSearch RouteSearch.mode}
     * @param passedByPoints 路线途径点
     */
    public void calculateRouteAsyn(int queryType, RouteSearch.FromAndTo fromAndTo, int mode,
                                       List<LatLonPoint> passedByPoints);

    // 发送路径规划结果到远程设备(手表)
    /**
     * 发送公交路径规划结果给远程设备
     * @param busRouteResult 高德API返回的公交路径规划结果
     * @return 是否成功发送,注意发送成功不代表远程设备也成功接收
     */
    public boolean sendBusRouteResultToRemote(BusRouteResult busRouteResult);

    /**
     * 发送驾车路径规划结果给远程设备
     * @param driveRouteResult 高德API返回的驾车路径规划结果
     * @return 是否成功发送,注意发送成功不代表远程设备也成功接收
     */
    public boolean sendDriveRouteResultToRemote(DriveRouteResult driveRouteResult);

    /**
     * 发送骑行路径规划结果给远程设备
     * @param rideRouteResult 高德API返回的骑行路径规划结果
     * @return 是否成功发送,注意发送成功不代表远程设备也成功接收
     */
    public boolean sendRideRouteResultToRemote(RideRouteResult rideRouteResult);

    /**
     * 发送步行路径规划结果给远程设备
     * @param walkRouteResult 高德API返回的步行路径规划结果
     * @return 是否成功发送,注意发送成功不代表远程设备也成功接收
     */
    public boolean sendWalkRouteResultToRemote(WalkRouteResult walkRouteResult);

    // 注意使用以上方法发送路线结果时,
    // 需要在远端设备通过RemoteSearchServiceManager注册监听用来接收路线结果
    /**
     * 用于注册响应远端路径规划的监听器
     *
     * @param listener 监听器对象
     *
     * @return true 注册成功, false 注册失败
     */
    public boolean registerRemoteRouteSearchListener(RemoteRouteSearchListener listener);

    /**
     * 注销响应远端路径规划的监听器 
     *
     * @param listener 监听器对象
     */
    public void unregisterRemoteRouteSearchListener(RemoteRouteSearchListener listener);

iOS CODE:

    // 获取代理对象
    IWDSSearchServiceProxy *proxy = [IWDSSearchServiceProxy shareInstance];

    /**
     * 设置高德API key
     */
    - (void)setApiKey:(NSString *)key;

    /**
     * 公交路径规划,公交路径规划不支持添加途径点
     */
    - (void)calculateBusRouteAsynByOrigin:(AMapGeoPoint *)origin destination:(AMapGeoPoint *)destination mode:(int)mode city:(NSString *)city destinationCity:(NSString *)destinationCity nightFlag:(BOOL)nightFlag requireExtension:(BOOL)requireExtension;

    /**
     * 驾车路径规划,支持添加最多16个途径点,支持设置避让区域和避让道路
     */
    - (void)calculateDriveRouteAsynByOrigin:(AMapGeoPoint *)origin destination:(AMapGeoPoint *)destination mode:(int)mode passedByPoints:(NSArray *)passedByPoints avoidpolygons:(NSArray<AMapGeoPolygon *> *)avoidpolygons avoidroad:(NSString *)avoidroad requireExtension:(BOOL)requireExtension;

    /**
     * 骑行或步行路径规划,可添加多个途径点
     */
    - (void)calculateRouteAsynByType:(int)queryType origin:(AMapGeoPoint *)origin destination:(AMapGeoPoint *)destination mode:(int)mode passedByPoints:(NSArray *)passedByPoints;

    /**
     * 发送公交路径规划结果到远程设备
     */
    - (BOOL)sendBusRouteResultToRemote:(AMapRouteSearchResponse *)result request:(AMapTransitRouteSearchRequest *)request;

    /**
     * 发送驾车路径规划结果到远程设备
     */
    - (BOOL)sendDriveRouteResultToRemote:(AMapRouteSearchResponse *)result request:(AMapDrivingRouteSearchRequest *)request;

    /**
     * 发送骑行路径规划结果到远程设备
     */
    - (BOOL)sendRideRouteResultToRemote:(AMapRouteSearchResponse *)result request:(AMapRidingRouteSearchRequest *)request;

    /**
     * 发送步行路径规划结果到远程设备
     */
    - (BOOL)sendWalkRouteResultToRemote:(AMapRouteSearchResponse *)result request:(AMapWalkingRouteSearchRequest *)request;

The Remote Search service is a subservice of the IWDS system service, which is used in accordance with the IWDS service framework.

    ServiceClient mServiceClient = new ServiceClient(mContext,
                RemoteDeviceServiceManager.SERVICE_REMOTE_SEARCH, mConnectionCallbacks);
    mServiceClient.connect();
    //在 mConnectionCallbacks 的回调函数onConnected中获取RemoteSearchServiceManager实例

    @Override
    public void onConnected(ServiceClient serviceClient) {
        m_serviceManager = (RemoteSearchServiceManager) m_client
                .getServiceManagerContext();
        // 注册远程服务状态监听
        m_serviceManager.registerRemoteStatusListener(m_remoteStatusListener);

        // 注册远程路径规划监听(该监听适用于接收手机端路径规划的结果,由手机端主动触发)
        m_serviceManager.registerRemoteRouteSearchListener(m_routeSearchListener);
    }

    @Override
    public void onDisconnected(ServiceClient serviceClient, boolean unexpected) {
        // 在服务断开后注销监听器
        m_serviceManager.unregisterRemoteStatusListener(m_remoteStatusListener);
        m_serviceManager.unregisterRemoteRouteSearchListener(m_routeSearchListener);
    }

    @Override
    public void onConnectFailed(ServiceClient serviceClient,
                                ConnectFailedReason reason) {
    }

Interface

Demo

Demo:elf/samples/RemoteSearchTest

Note

1 when using iwds-service-ui-jar.jar, if at the same time need to use AMap SDK (AMap_Search_V3.6.1_20161122.jar), don't add AMap_Search_V3.6.1_20161122.jar in engineering libs, otherwise it will result in a compile error;

2.When using Iwds.framework, if at the same time need to use AMap SDK (AMapFoundationKit.framework, AMapSearchKit.framework), please Iwds.framework in the Frameworks folder to delete, otherwise there will be a kind of conflict.