मेरे पास कुछ सी # कोड है जो Google के पॉलीलाइन एल्गोरिदम का उपयोग करके एन्कोड किए गए मानचित्र पथ को डीकोड करता है और इसे VB.NET में परिवर्तित करने की कोशिश कर रहा हूं।सी # से वीबीएनईटी रूपांतरण (Google पॉलीलाइन एल्गोरिदम डीकोडर)
Collection<Double> decodePolyline(string polyline)
{
if (polyline == null || polyline == "") return null;
char[] polylinechars = polyline.ToCharArray();
int index = 0;
Collection<Double> points = new Collection<Double>();
int currentLat = 0;
int currentLng = 0;
int next5bits;
int sum;
int shifter;
while (index < polylinechars.Length)
{
// calculate next latitude
sum = 0;
shifter = 0;
do
{
next5bits = (int)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 = (int)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);
points.Add(Convert.ToDouble(currentLat)/100000.0);
points.Add(Convert.ToDouble(currentLng)/100000.0);
}
return points;
}
यहाँ VB.NET code- अक्षांश देशांतर के लिए नहीं बल्कि काम करता है:
यहाँ सी # कोड है, जो पूरी तरह से काम करता है।
Public Function decodePolyline(ByVal polyline As String) As Collection(Of Double)
If polyline Is Nothing OrElse polyline = "" Then Return Nothing
Dim polylinechars As Char() = polyline.ToCharArray()
Dim points As New Collection(Of Double)
Dim currentLat As Integer = 0
Dim currentLng As Integer = 0
Dim next5bits As Integer
Dim sum As Integer
Dim shifter As Integer
For index As Integer = 0 To polylinechars.Length - 1
'calculate next latitude
sum = 0
shifter = 0
Do
index += 1
next5bits = AscW(polylinechars(index)) - 63
sum = sum Or (next5bits And 31) << shifter
shifter += 5
Loop While next5bits >= 32 AndAlso index < polylinechars.Length
If index >= polylinechars.Length Then
Exit For
End If
currentLat += If((sum And 1) = 1, Not (sum >> 1), (sum >> 1))
'calculate next longitude
sum = 0
shifter = 0
Do
index += 1
next5bits = AscW(polylinechars(index)) - 63
sum = sum Or (next5bits And 31) << shifter
shifter += 5
Loop While next5bits >= 32 AndAlso index < polylinechars.Length
If index >= polylinechars.Length AndAlso next5bits >= 32 Then
Exit For
End If
currentLng += If((sum And 1) = 1, Not (sum >> 1), (sum >> 1))
points.Add(Convert.ToDouble(currentLat)/100000.0)
points.Add(Convert.ToDouble(currentLng)/100000.0)
Next
Return points
End Function
क्या गुम है?
संपादित करें: समस्या का समाधान (नीचे दिए गए मेरे उत्तर में सही कोड, जिसे मैं 2 दिनों के लिए उत्तर के रूप में नहीं चुन सकता)।
(मेरा उत्तर नष्ट कर दिया के रूप में मुझे नहीं लगता कि यह मदद कर रहा था है और मेरी वीबी केवल पढ़ने के लिए विकृत हो गया है, तो मैं करके इसे ठीक नहीं कर सकते हैं:
यहाँ सुधारा VB.NET कोड है अकेले नज़र) –
किस तरह से यह काम नहीं करता है? क्या यह संकलित करता है? गलत परिणाम दिखाता है, सी # संस्करण से अलग? – tiago2014
अक्षांश के लिए गलत आउटपुट देता है। – amb9800