3232import java .io .UnsupportedEncodingException ;
3333import java .net .URLEncoder ;
3434import java .util .ArrayList ;
35+ import java .util .List ;
3536import java .util .Locale ;
3637
3738import okhttp3 .Call ;
@@ -634,10 +635,10 @@ public void onFailure(String errorMessage) {
634635 */
635636 public void direction (LatLng start , LatLng end , final GeoRoutingResultListener completionHandler ) {
636637
637- ArrayList <Pair < LatLng , LatLng >> points = new ArrayList <>();
638- points .add (new Pair <>( start , end ) );
638+ ArrayList <LatLng > destinations = new ArrayList <>();
639+ destinations .add (end );
639640
640- direction (points , false , new Locale ("fa" ), completionHandler );
641+ direction (start , destinations , false , new Locale ("fa" ), completionHandler );
641642 }
642643
643644 /**
@@ -651,53 +652,54 @@ public void direction(LatLng start, LatLng end, final GeoRoutingResultListener c
651652 */
652653 public void directionWithInstructions (LatLng start , LatLng end , Locale locale , final GeoRoutingResultListener completionHandler ) {
653654
654- ArrayList <Pair < LatLng , LatLng >> points = new ArrayList <>();
655- points .add (new Pair <>( start , end ) );
655+ ArrayList <LatLng > destinations = new ArrayList <>();
656+ destinations .add (end );
656657
657- direction (points , true , locale , completionHandler );
658+ direction (start , destinations , true , locale , completionHandler );
658659 }
659660
660661 /**
661- * This method calculates the detailed coordinates of the route between two consecutive points. It can be called with up to 50 pairs
662+ * This method calculates the detailed coordinates of the route between consecutive points. It can be called with up to 50 coordinates.
662663 *
663- * @param coordinatePairs Set up to 50 pairs of (Start, End).
664+ * @param start Starting coordinate.
665+ * @param destinations Set up to 49 coordinates.
664666 * @param completionHandler The handler to notify when Geo Routing results are ready with success or error.
665667 * The handler methods are called on UIThread.
666668 */
667- public void direction (ArrayList < Pair < LatLng , LatLng >> coordinatePairs , final GeoRoutingResultListener completionHandler ) {
668- direction (coordinatePairs , false , new Locale ("fa" ), completionHandler );
669+ public void direction (LatLng start , List < LatLng > destinations , final GeoRoutingResultListener completionHandler ) {
670+ direction (start , destinations , false , new Locale ("fa" ), completionHandler );
669671 }
670672
671673
672674 /**
673675 * This method calculates the detailed coordinates of the route between two consecutive points with textual instructions. It can be called with up to 50 pairs
674676 *
675- * @param coordinatePairs Set up to 50 pairs of (Start, End).
677+ * @param start Starting coordinate.
678+ * @param destinations Set up to 49 coordinates.
676679 * @param locale Identifier for language. Currently Locale("fa") and Locale("en") are supported.
677680 * @param completionHandler The handler to notify when Geo Routing results are ready with success or error.
678681 * The handler methods are called on UIThread.
679682 */
680- public void directionWithInstructions (ArrayList < Pair < LatLng , LatLng >> coordinatePairs , Locale locale , final GeoRoutingResultListener completionHandler ) {
681- direction (coordinatePairs , true , locale , completionHandler );
683+ public void directionWithInstructions (LatLng start , List < LatLng > destinations , Locale locale , final GeoRoutingResultListener completionHandler ) {
684+ direction (start , destinations , true , locale , completionHandler );
682685 }
683686
684- private void direction (ArrayList < Pair < LatLng , LatLng >> coordinatePairs , Boolean shouldShowInstructions , Locale locale , final GeoRoutingResultListener completionHandler ) {
687+ private void direction (LatLng start , List < LatLng > destinations , Boolean shouldShowInstructions , Locale locale , final GeoRoutingResultListener completionHandler ) {
685688
686- StringBuilder pairs = new StringBuilder ();
687- String delimiter = "" ;
688- for (Pair <LatLng , LatLng > locationPair : coordinatePairs ) {
689- if (locationPair .first == null || locationPair .second == null ) {
690- continue ;
691- }
692- pairs .append (delimiter ).append (String .format (Locale .ENGLISH , "%1$s,%2$s;%3$s,%4$s" , locationPair .first .getLatitude (),
693- locationPair .first .getLongitude (), locationPair .second .getLatitude (), locationPair .second .getLongitude ()));
694- delimiter = "/" ;
689+ StringBuilder points = new StringBuilder ();
690+
691+ points .append (String .format (Locale .ENGLISH , "%1$s,%2$s" , start .getLatitude (),
692+ start .getLongitude ()));
693+
694+ for (LatLng destination : destinations ) {
695+ points .append (";" ).append (String .format (Locale .ENGLISH , "%1$s,%2$s" , destination .getLatitude (),
696+ destination .getLongitude ()));
695697 }
696698
697699 String url = String .format (Locale .ENGLISH ,
698700 authManager .getAPIBaseURL () + "direction/%1$s/%2$s?instructions=%3$s&locale=%4$s" ,
699701 directionID .toString (),
700- pairs .toString (),
702+ points .toString (),
701703 shouldShowInstructions ? "true" : "false" ,
702704 locale .getLanguage ().contains ("fa" ) ? "fa" : "en"
703705 );
@@ -742,7 +744,7 @@ public void onFailure(String errorMessage) {
742744 * @param completionHandler The handler to notify when static image Bitmap is ready with success or error.
743745 * The handler methods are called on UIThread.
744746 */
745- public void staticMap (int width , int height , int zoomLevel , @ Nullable LatLng centerPoint , @ Nullable ArrayList <StaticMarker > markers , final @ NonNull StaticMapImageResultListener completionHandler ) {
747+ public void staticMap (int width , int height , int zoomLevel , @ Nullable LatLng centerPoint , @ Nullable List <StaticMarker > markers , final @ NonNull StaticMapImageResultListener completionHandler ) {
746748 int validZoomLevel = Math .min (17 , Math .max (zoomLevel , 6 ));
747749 String paramPosition = centerPoint != null ? String .format (Locale .ENGLISH , "%f,%f,%d" , centerPoint .getLatitude (), centerPoint .getLongitude (), validZoomLevel ) : "auto" ;
748750
0 commit comments