Полилиния декодирования Flutter Web - PullRequest
0 голосов
/ 12 июля 2020

Я использую этот код для декодирования ломаной линии

 List<LatLng> poly = [];
 int index = 0, len = encoded.length;
 int lat = 0, lng = 0;


 while (index < len) {
   int b, shift = 0, result = 0;
   do {
     b = codePointAt(encoded, index++) - 63;
     result |= (b & 0x1f) << shift;
     shift += 5;
   } while (b >= 0x20);
   int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
   lat += dlat;

   shift = 0;
   result = 0;
   do {
     b = codePointAt(encoded, index++) - 63;
     result |= (b & 0x1f) << shift;
     shift += 5;

   } while (b >= 0x20);

   print('result: $result');

   int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
   print('dlng: $dlng');


   lng += dlng;

   print(lat);
   print(lng);

   LatLng p =
   new LatLng((lat / 1E5).toDouble(), (lng / 1E5).toDouble());
   poly.add(p);
 }
 return poly;
}

Он работает на android, но когда я пытаюсь запустить его в Интернете, координаты не совпадают, даже не близки к тем же . Это вывод в Интернете, обратите внимание, что dlng не такой, как в android

dlng: 4287266948
4293759243
4287266948
result: 827
dlng: 4294966882
8588726368
8582233830
result: 115
dlng: 4294967238
12883693602
12877201068
result: 39
dlng: 4294967276
17178660801
17172168344
result: 134
dlng: 67
21473627632
17172168411
result: 125
dlng: 4294967233
25768594919
21467135644
result: 377
dlng: 4294967107
30063562176
25762102751
result: 5643
dlng: 4294964474
34358529076
30057067225
result: 976
dlng: 488
34358529130
30057067713
result: 626
dlng: 313
38653494604
30057068026
result: 191
dlng: 4294967200
42948461899
34352035226
result: 8
dlng: 4
47243429151
34352035230
[LatLng(90, 32.66947999999684), LatLng(90, 142.33830000000307), LatLng(90, -107.98931999999331), LatLng(90, 1.6834399999934249), LatLng(90, 1.684110000001965), LatLng(90, 111.3564400000032), LatLng(90, -138.97248999998556), LatLng(90, -29.32774999999674), LatLng(90, -29.3228699999745), LatLng(90, -29.319740000006277), LatLng(90, 80.35226000001421), LatLng(90, 80.35230000002775)]

Это вывод на android

I/flutter ( 5220): dlng: -7700348
I/flutter ( 5220): -1208053
I/flutter ( 5220): -7700348
I/flutter ( 5220): result: 827
I/flutter ( 5220): dlng: -414
I/flutter ( 5220): -1208224
I/flutter ( 5220): -7700762
I/flutter ( 5220): result: 115
I/flutter ( 5220): dlng: -58
I/flutter ( 5220): -1208286
I/flutter ( 5220): -7700820
I/flutter ( 5220): result: 39
I/flutter ( 5220): dlng: -20
I/flutter ( 5220): -1208383
I/flutter ( 5220): -7700840
I/flutter ( 5220): result: 134
I/flutter ( 5220): dlng: 67
I/flutter ( 5220): -1208848
I/flutter ( 5220): -7700773
I/flutter ( 5220): result: 125
I/flutter ( 5220): dlng: -63
I/flutter ( 5220): -1208857
I/flutter ( 5220): -7700836
I/flutter ( 5220): result: 377
I/flutter ( 5220): dlng: -189
I/flutter ( 5220): -1208896
I/flutter ( 5220): -7701025
I/flutter ( 5220): result: 5643
I/flutter ( 5220): dlng: -2822
I/flutter ( 5220): -1209292
I/flutter ( 5220): -7703847
I/flutter ( 5220): result: 976
I/flutter ( 5220): dlng: 488
I/flutter ( 5220): -1209238
I/flutter ( 5220): -7703359
I/flutter ( 5220): result: 626
I/flutter ( 5220): dlng: 313
I/flutter ( 5220): -1211060
I/flutter ( 5220): -7703046
I/flutter ( 5220): result: 191
I/flutter ( 5220): dlng: -96
I/flutter ( 5220): -1211061
I/flutter ( 5220): -7703142
I/flutter ( 5220): result: 8
I/flutter ( 5220): dlng: 4
I/flutter ( 5220): -1211105
I/flutter ( 5220): -7703138
I/flutter ( 5220): [LatLng(-12.08053, -77.00348), LatLng(-12.08224, -77.00762), LatLng(-12.08286, -77.0082), LatLng(-12.08383, -77.0084), LatLng(-12.08848, -77.00773), LatLng(-12.08857, -77.00836), LatLng(-12.08896, -77.01025), LatLng(-12.09292, -77.03847), LatLng(-12.09238, -77.03359), LatLng(-12.1106, -77.03046), LatLng(-12.11061, -77.03142), LatLng(-12.11105, -77.03138)]

Я не совсем конечно, но я думаю, что ошибка в этой части, я не уверен, как это исправить

int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
...