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

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

YandexLocation.vb 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.featureMember.[0].GeoObject.Point.pos
  24. Coordinates = MyJson("response")("GeoObjectCollection")("featureMember")(0)("GeoObject")("Point")("pos")
  25. End Sub
  26. Public Function lat()
  27. Dim cord As Array = Split(Coordinates, " ")
  28. Dim l1 As Double = Convert.ToDouble(cord(1))
  29. Return l1
  30. End Function
  31. Public Function lng()
  32. Dim cord As Array = Split(Coordinates, " ")
  33. Dim l1 As Double = Convert.ToDouble(cord(0))
  34. Return l1
  35. End Function
  36. End Class
  37. Sub Main()
  38. Dim loc As YandexLocatin = New YandexLocatin("4-ый Загородный переулок, дом 20, Минск, Беларусь")
  39. End Sub
  40. End Module