-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pushed decode method to toaster library
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/BaatoUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.kathmandulivinglabs.navigationlibrary; | ||
|
||
import com.kathmandulivinglabs.navigationlibrary.models.Geometry; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class BaatoUtil { | ||
public static Geometry getGeoJsonFromEncodedPolyLine(String encoded) { | ||
return new Geometry("LineString", decodePolyline(encoded, false)); | ||
} | ||
|
||
public static List<List<Double>> decodePolyline(String encoded, boolean is3D) { | ||
List<List<Double>> pointList = new ArrayList<>(); | ||
int index = 0; | ||
int len = encoded.length(); | ||
int lat = 0, lng = 0, ele = 0; | ||
while (index < len) { | ||
// latitude | ||
int b, shift = 0, result = 0; | ||
do { | ||
b = encoded.charAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
int deltaLatitude = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | ||
lat += deltaLatitude; | ||
|
||
// longitute | ||
shift = 0; | ||
result = 0; | ||
do { | ||
b = encoded.charAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
int deltaLongitude = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | ||
lng += deltaLongitude; | ||
|
||
if (is3D) { | ||
// elevation | ||
shift = 0; | ||
result = 0; | ||
do { | ||
b = encoded.charAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
int deltaElevation = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | ||
ele += deltaElevation; | ||
List<Double> list = new ArrayList<>(); | ||
list.add((double) lat / 1e5); | ||
list.add((double) lng / 1e5); | ||
list.add((double) ele / 100); | ||
pointList.add(list); | ||
} else { | ||
List<Double> list = new ArrayList<>(); | ||
list.add((double) lat / 1e5); | ||
list.add((double) lng / 1e5); | ||
pointList.add(list); | ||
} | ||
} | ||
return pointList; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
toasterlibrary/src/main/java/com/kathmandulivinglabs/navigationlibrary/models/Geometry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.kathmandulivinglabs.navigationlibrary.models; | ||
|
||
public class Geometry { | ||
public String type; | ||
public Object coordinates; | ||
|
||
public Geometry(String type, Object coordinates) { | ||
this.type = type; | ||
this.coordinates = coordinates; | ||
} | ||
} |