add route search api
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package com.mogo.map.impl.amap.search;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.BusRouteResult;
|
||||
import com.amap.api.services.route.DrivePath;
|
||||
import com.amap.api.services.route.DriveRouteResult;
|
||||
import com.amap.api.services.route.DriveStep;
|
||||
import com.amap.api.services.route.RideRouteResult;
|
||||
import com.amap.api.services.route.RouteSearch;
|
||||
import com.amap.api.services.route.WalkRouteResult;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearchListener;
|
||||
import com.mogo.map.search.drive.MogoRoadSearchQuery;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class RoadSearchClient implements IMogoRoadSearch, RouteSearch.OnRouteSearchListener {
|
||||
|
||||
private static final String TAG = "DriveSearchClient";
|
||||
|
||||
private RouteSearch mRouteSearch;
|
||||
private IMogoRoadSearchListener mListener;
|
||||
|
||||
@Override
|
||||
public void searchRoadPath( Context context,
|
||||
MogoRoadSearchQuery query ) {
|
||||
|
||||
if ( query == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !checkPoint( query.mStart, "起点坐标" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !checkPoint( query.mTarget, "终点坐标" ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo( ObjectUtils.fromMogo( query.mStart ), ObjectUtils.fromMogo( query.mTarget ) );
|
||||
final List< LatLonPoint > latLonPointWays = new ArrayList<>();
|
||||
if ( query.mWays != null ) {
|
||||
for ( MogoLatLng wayPoint : query.mWays ) {
|
||||
if ( checkPoint( wayPoint, "途经点" ) ) {
|
||||
latLonPointWays.add( ObjectUtils.fromMogo( wayPoint ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RouteSearch.DriveRouteQuery searchQuery = new RouteSearch.DriveRouteQuery( fromAndTo, RouteSearch.DRIVING_SINGLE_SHORTEST, latLonPointWays, null, "" );
|
||||
if ( mRouteSearch == null ) {
|
||||
mRouteSearch = new RouteSearch( context );
|
||||
}
|
||||
mRouteSearch.calculateDriveRouteAsyn( searchQuery );
|
||||
}
|
||||
|
||||
private boolean checkPoint( MogoLatLng latLng, String msg ) {
|
||||
if ( latLng == null ) {
|
||||
Logger.e( TAG, msg + " is null" );
|
||||
return false;
|
||||
}
|
||||
if ( latLng.lat <= 0d || latLng.lon <= 0d ) {
|
||||
Logger.e( TAG, msg + " is not a valid " );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoadPathSearchListener( IMogoRoadSearchListener listener ) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched( BusRouteResult busRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDriveRouteSearched( DriveRouteResult driveRouteResult, int i ) {
|
||||
if ( mListener == null ) {
|
||||
return;
|
||||
}
|
||||
List< MogoLatLng > points = new ArrayList<>();
|
||||
|
||||
if ( driveRouteResult == null
|
||||
|| driveRouteResult.getPaths() == null
|
||||
|| driveRouteResult.getPaths().isEmpty() ) {
|
||||
mListener.onDrivePathSearched( null );
|
||||
return;
|
||||
}
|
||||
DrivePath drivePath = driveRouteResult.getPaths().get( 0 );
|
||||
List< DriveStep > steps = drivePath.getSteps();
|
||||
if ( steps == null || steps.isEmpty() ) {
|
||||
mListener.onDrivePathSearched( null );
|
||||
return;
|
||||
}
|
||||
for ( DriveStep step : steps ) {
|
||||
List< LatLonPoint > polylineList = step.getPolyline();
|
||||
if ( polylineList == null || polylineList.isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
for ( LatLonPoint latLonPoint : polylineList ) {
|
||||
MogoLatLng latLng = ObjectUtils.fromAMap( latLonPoint );
|
||||
if ( latLng == null ) {
|
||||
continue;
|
||||
}
|
||||
points.add( latLng );
|
||||
}
|
||||
}
|
||||
mListener.onDrivePathSearched( points );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched( WalkRouteResult walkRouteResult, int i ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched( RideRouteResult rideRouteResult, int i ) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.map.search.drive;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 驾驶路线
|
||||
*/
|
||||
public interface IMogoRoadSearch {
|
||||
|
||||
void searchRoadPath( Context context, MogoRoadSearchQuery query );
|
||||
|
||||
void setRoadPathSearchListener( IMogoRoadSearchListener listener );
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.map.search.drive;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public interface IMogoRoadSearchListener {
|
||||
|
||||
void onDrivePathSearched( List< MogoLatLng > points );
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.map.search.drive;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MogoRoadSearchQuery {
|
||||
|
||||
public MogoLatLng mStart;
|
||||
public MogoLatLng mTarget;
|
||||
public List<MogoLatLng> mWays;
|
||||
|
||||
public MogoRoadSearchQuery() {
|
||||
}
|
||||
|
||||
public MogoRoadSearchQuery setStart( MogoLatLng start ) {
|
||||
this.mStart = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MogoRoadSearchQuery setTarget( MogoLatLng target ) {
|
||||
this.mTarget = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MogoRoadSearchQuery setWays( List< MogoLatLng > ways ) {
|
||||
this.mWays = ways;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.mogo.map;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.map.impl.amap.search.RoadSearchClient;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearchListener;
|
||||
import com.mogo.map.search.drive.MogoRoadSearchQuery;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/1
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MogoRoadSearch implements IMogoRoadSearch {
|
||||
|
||||
private RoadSearchClient mDelegate;
|
||||
|
||||
public MogoRoadSearch() {
|
||||
mDelegate = new RoadSearchClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void searchRoadPath( Context context, MogoRoadSearchQuery query ) {
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.searchRoadPath( context, query );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoadPathSearchListener( IMogoRoadSearchListener listener ) {
|
||||
if ( mDelegate != null ) {
|
||||
mDelegate.setRoadPathSearchListener( listener );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,10 +119,10 @@
|
||||
<dimen name="module_map_navi_next_info_road_turn_marginRight">8px</dimen>
|
||||
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">526px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">83px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">82px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">550px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">208px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">100px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">100px</dimen>
|
||||
<dimen name="module_ext_common_corner">16px</dimen>
|
||||
<dimen name="module_ext_north_goneMarginTop">142px</dimen>
|
||||
<dimen name="module_ext_button_width">66px</dimen>
|
||||
|
||||
@@ -116,10 +116,10 @@
|
||||
<dimen name="module_map_navi_next_info_road_turn_marginRight">15px</dimen>
|
||||
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">950px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">320px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">1000px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">390px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">200px</dimen>
|
||||
<dimen name="module_ext_north_goneMarginTop">240px</dimen>
|
||||
<dimen name="module_ext_common_corner">30px</dimen>
|
||||
<dimen name="module_ext_button_width">120px</dimen>
|
||||
|
||||
@@ -113,10 +113,10 @@
|
||||
<dimen name="module_map_navi_next_info_road_turn_marginRight">15px</dimen>
|
||||
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">950px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">320px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">1000px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">390px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">200px</dimen>
|
||||
<dimen name="module_ext_common_corner">30px</dimen>
|
||||
<dimen name="module_ext_north_goneMarginTop">240px</dimen>
|
||||
<dimen name="module_ext_button_width">120px</dimen>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<dimen name="module_map_calculate_path_display_overview_right_margin">80px</dimen>
|
||||
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">526px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">83px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">82px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">550px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">208px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">100px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">100px</dimen>
|
||||
</resources>
|
||||
@@ -6,8 +6,8 @@
|
||||
<dimen name="module_map_calculate_path_display_overview_right_margin">80px</dimen>
|
||||
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">950px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">320px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">1000px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">390px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">200px</dimen>
|
||||
</resources>
|
||||
@@ -6,8 +6,8 @@
|
||||
<dimen name="module_map_calculate_path_display_overview_bottom_margin">61px</dimen>
|
||||
<dimen name="module_map_calculate_path_display_overview_right_margin">80px</dimen>
|
||||
<!-- 导航查看全程显示范围-->
|
||||
<dimen name="module_map_display_overview_left_margin">950px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">320px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">150px</dimen>
|
||||
<dimen name="module_map_display_overview_left_margin">1000px</dimen>
|
||||
<dimen name="module_map_display_overview_top_margin">390px</dimen>
|
||||
<dimen name="module_map_display_overview_bottom_margin">200px</dimen>
|
||||
<dimen name="module_map_display_overview_right_margin">200px</dimen>
|
||||
</resources>
|
||||
@@ -4,14 +4,11 @@ import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
import com.mogo.map.listener.IMogoHosListenerRegister;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.listener.IMogoMapListenerRegister;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
import com.mogo.map.navi.IMogoNaviListenerRegister;
|
||||
import com.mogo.map.overlay.IMogoOverlayManager;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
@@ -107,4 +104,11 @@ public interface IMogoMapService extends IProvider {
|
||||
* @return
|
||||
*/
|
||||
IMogoOverlayManager getOverlayManager( Context context );
|
||||
|
||||
/**
|
||||
* 路线搜索
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IMogoRoadSearch getRoadSearchApi();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.service.impl.map;
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.MogoRoadSearch;
|
||||
import com.mogo.map.MogoGeoSearch;
|
||||
import com.mogo.map.MogoInputtipsSearch;
|
||||
import com.mogo.map.MogoLocationClient;
|
||||
@@ -17,6 +18,7 @@ import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.overlay.IMogoOverlayManager;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
import com.mogo.map.search.geo.IMogoGeoSearch;
|
||||
import com.mogo.map.search.inputtips.IMogoInputtipsSearch;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
@@ -85,6 +87,11 @@ public class MogoMapService implements IMogoMapService {
|
||||
return MogoOverlayManager.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoRoadSearch getRoadSearchApi() {
|
||||
return new MogoRoadSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user