Biggi/YandexLocation: Микробиблиотека для получения координат по адресу - SVN.BY: Go Git Service

Микробиблиотека для получения координат по адресу

YandexLocation.vb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. Imports System.Net
  2. Imports Newtonsoft
  3. Imports Newtonsoft.Json.Linq
  4. Module YandexLocation
  5. Public Class YandexLocatin
  6. Dim adres As String
  7. Dim respone As String
  8. Dim Coordinates As String
  9. Sub New(adres As String)
  10. Me.adres = adres
  11. Using WebClient = New WebClient
  12. WebClient.Encoding = System.Text.Encoding.UTF8
  13. Me.respone = WebClient.DownloadString("https://geocode-maps.yandex.ru/1.x/?format=json&geocode=" + Replace_Adres())
  14. End Using
  15. JSONDECODE()
  16. End Sub
  17. Private Function Replace_Adres()
  18. Dim url_adres As String = Replace(adres, " ", "+")
  19. Return url_adres
  20. End Function
  21. Private Sub JSONDECODE()
  22. Dim MyJson As JObject = Json.JsonConvert.DeserializeObject(respone)
  23. '[JSON].response.GeoObjectCollection.metaDataProperty.GeocoderResponseMetaData.results
  24. '[JSON].response.GeoObjectCollection.featureMember.[0].GeoObject.Point.pos
  25. If MyJson("response")("GeoObjectCollection")("metaDataProperty")("GeocoderResponseMetaData")("results").ToString = "0" Then
  26. Coordinates = Nothing
  27. Else
  28. Coordinates = MyJson("response")("GeoObjectCollection")("featureMember")(0)("GeoObject")("Point")("pos")
  29. End If
  30. End Sub
  31. Public Function lat()
  32. If Coordinates IsNot Nothing Then
  33. Dim cord As Array = Split(Coordinates, " ")
  34. Dim l1 As String = (cord(1))
  35. Return l1
  36. Else
  37. Return ""
  38. End If
  39. End Function
  40. Public Function lng()
  41. If Coordinates IsNot Nothing Then
  42. Dim cord As Array = Split(Coordinates, " ")
  43. Dim l1 As String = (cord(0))
  44. Return l1
  45. Else
  46. Return ""
  47. End If
  48. End Function
  49. End Class
  50. End Module