gpt4 book ai didi

google-maps - 如何在 dartlang 中使用 google.maps.geometry.encoding.decodePath?

转载 作者:行者123 更新时间:2023-12-03 04:17:00 25 4
gpt4 key购买 nike

如何使用函数解码字符串?

我找不到原生库的方法

var path = google.maps.geometry.encoding.decodePath(encodedStr);

----- 解决方案----
String str = "ern[pd_cMiAa@\q@l@kAPY`Ad@hCnAr@^HOzAaClCgElBsCfBhA";
var decodedPath = encoding.decodePath(str);
var estimate_line = new Polyline(new PolylineOptions()
..path = decodedPath
..geodesic = true
..strokeColor = '#FF0000'
..strokeOpacity = 1.0
..strokeWeight = 2
..map = map
);

最佳答案

在这里,我已经在原生 Dart 中实现了
编码引用:https://developers.google.com/maps/documentation/utilities/polylinealgorithm这里解释编码算法

import 'dart:io';

main()
{
var z="eo~fMzva{Fl|cuTgh~oU~bxjDhpptb@";
print(decode(z));
}

/** function to decode the string ****/
List decode(var a)
{
var list=a.codeUnits;
var lList=new List();
int index=0;
int len=a.length;
int c=0;

// repeating until all attributes are decoded
do
{
var shift=0;
int result=0;

// for decoding value of one attribute
do
{
c=list[index]-63;
result|=(c & 0x1F)<<(shift*5);
index++;
shift++;
}while(c>=32);
/* if value is negetive then bitwise not the value */
if(result & 1==1)
{
result=~result;
}
var result1 = (result >> 1) * 0.00001;
lList.add(result1);
}while(index<len);

/*adding to previous value as done in encoding */
for(var i=2;i<lList.length;i++)
lList[i]+=lList[i-2];
return lList;
}

关于google-maps - 如何在 dartlang 中使用 google.maps.geometry.encoding.decodePath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43991533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com