Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a8829165e8
3 changed files with 11 additions and 4 deletions
|
@ -5,17 +5,19 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class GeoPolylineParserUtil {
|
||||
|
||||
public static final double PRECISION_6 = 1E6;
|
||||
public static final double PRECISION_5 = 1E5;
|
||||
/**
|
||||
* Parses Google esque polyline
|
||||
*
|
||||
* @param encoded The polyline as a String
|
||||
* @return {@link List<LatLon>}
|
||||
*/
|
||||
public static List<LatLon> parse(final String encoded) {
|
||||
public static List<LatLon> parse(final String encoded, double precision) {
|
||||
List<LatLon> track = new ArrayList<LatLon>();
|
||||
int index = 0;
|
||||
int lat = 0, lng = 0;
|
||||
double precision = 1E5;
|
||||
|
||||
while (index < encoded.length()) {
|
||||
int b, shift = 0, result = 0;
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.util;
|
|||
import net.osmand.data.LatLon;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -13,6 +14,8 @@ import org.junit.Test;
|
|||
public class GeoPolylineParserUtilTest {
|
||||
@Test
|
||||
public void testDecode() {
|
||||
|
||||
|
||||
Assert.assertEquals(Arrays.asList(
|
||||
new LatLon(52.503032, 13.420526),
|
||||
new LatLon(52.503240, 13.420671),
|
||||
|
@ -83,6 +86,7 @@ public class GeoPolylineParserUtilTest {
|
|||
GeoPolylineParserUtil.parse("" +
|
||||
"o~occB{}brX_LaHyY{QaW}OoN{IoHuEcIcFeM}HoKyGuBsARmG`@yJVwKXaZIqT_@sUi@kNgCk`@wAePsCwTwDuTsG}Y" +
|
||||
"wIsZgFuMmB_F_HmQ}NoVgFyGoCsDmK}KgLaJuHeEgEyCiHcFgE}BeGo@mIKoQW{JwBwHeFmFmDePcNuJqIqk@sf@{EiE" +
|
||||
"mU}RoGkDwPoGeD|K{U`z@_Vpy@}\\pbAsJ}B}NqCyEy@yI}A_WeFeSyEqToJu^_Nmv@ge@{MyI}TcJkTeGcg@oMgCm@"));
|
||||
"mU}RoGkDwPoGeD|K{U`z@_Vpy@}\\pbAsJ}B}NqCyEy@yI}A_WeFeSyEqToJu^_Nmv@ge@{MyI}TcJkTeGcg@oMgCm@",
|
||||
GeoPolylineParserUtil.PRECISION_6));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1205,7 +1205,8 @@ public class RouteProvider {
|
|||
rs.close();
|
||||
} catch(IOException e){
|
||||
}
|
||||
List<LatLon> route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry"));
|
||||
List<LatLon> route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry"),
|
||||
GeoPolylineParserUtil.PRECISION_5);
|
||||
if (route.isEmpty()) {
|
||||
return new RouteCalculationResult("Route is empty");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue