Google java客户端api方向api给出了错误的路径
我正在使用Google的JAVA客户端API来获取路由,我正在发送这样的请求Google java客户端api方向api给出了错误的路径,java,google-maps,google-chrome,directions,google-directions-api,Java,Google Maps,Google Chrome,Directions,Google Directions Api,我正在使用Google的JAVA客户端API来获取路由,我正在发送这样的请求 DirectionsRoute[] routes = DirectionsApi.newRequest(context) .mode(TravelMode.DRIVING) .origin(start).destination(end)
DirectionsRoute[] routes = DirectionsApi.newRequest(context)
.mode(TravelMode.DRIVING)
.origin(start).destination(end)
.waypoints(wayPoints).await();
它也是返回路线,但若我绘制该路线,它并并并没有绘制在实际路线上,而是采用了图中所示的直线。
如何修复它?事实上,在请求之后我犯了一个错误,我得到了路由的结果,但它还包含编码器多段线对象,该对象由lat lang数组组成,一旦我们解码,我们将获得所有点,以便我们能够正确获得路由。
结果由路线数组组成每个元素由支腿数组组成(两点之间的路线细节)每个支腿由步骤组成最后每个步骤都对多段线进行了编码为了得到正确的latlang,你应该解码该多段线并使用它。非常感谢,你帮了我很多忙,我目前正在与xamarin合作,并使用此方法解码多段线
private List<LatLng> DecodePolyline(string encodedPoints)
{
if (string.IsNullOrWhiteSpace(encodedPoints))
{
return null;
}
int index = 0;
var polylineChars = encodedPoints.ToCharArray();
var poly = new List<LatLng>();
int currentLat = 0;
int currentLng = 0;
int next5Bits;
while (index < polylineChars.Length)
{
// calculate next latitude
int sum = 0;
int shifter = 0;
do
{
next5Bits = polylineChars[index++] - 63;
sum |= (next5Bits & 31) << shifter;
shifter += 5;
}
while (next5Bits >= 32 && index < polylineChars.Length);
if (index >= polylineChars.Length)
{
break;
}
currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
// calculate next longitude
sum = 0;
shifter = 0;
do
{
next5Bits = polylineChars[index++] - 63;
sum |= (next5Bits & 31) << shifter;
shifter += 5;
}
while (next5Bits >= 32 && index < polylineChars.Length);
if (index >= polylineChars.Length && next5Bits >= 32)
{
break;
}
currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
var mLatLng = new LatLng(Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0);
poly.Add(mLatLng);
}
return poly;
}
私有列表解码多段线(字符串编码点)
{
if(string.IsNullOrWhiteSpace(encodedPoints))
{
返回null;
}
int指数=0;
var polylineChars=encodedPoints.tocharray();
var poly=新列表();
int currentLat=0;
int currentLng=0;
整数位;
while(索引<多段线字符长度)
{
//计算下一纬度
整数和=0;
int移位器=0;
做
{
next5Bits=polylineChars[index++]-63;
总和|=(next5Bits&31)=32&&index<多段线字符长度);
如果(索引>=多段线字符长度)
{
打破
}
currentLat+=(总和&1)==1?~(总和>>1):(总和>>1);
//计算下一经度
总和=0;
移位器=0;
做
{
next5Bits=polylineChars[index++]-63;
总和|=(next5Bits&31)=32&&index<多段线字符长度);
如果(索引>=polylineChars.Length&&next5Bits>=32)
{
打破
}
currentLng+=(总和&1)==1?~(总和>>1):(总和>>1);
var mLatLng=新车床(换算为双精度(当前车床)/100000.0,换算为双精度(当前车床)/100000.0);
poly.Add(mLatLng);
}
返回多边形;
}
请提供一个演示该问题的示例。我从google java api“com.google.maps.DirectionsApi”中获取此指导api。