1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- Imports System.Net
- Imports Newtonsoft
- Imports Newtonsoft.Json.Linq
- Module YandexLocation
- Public Class YandexLocatin
- Dim adres As String
- Dim respone As String
- Dim Coordinates As String
- Sub New(adres As String)
- Me.adres = adres
- Using WebClient = New WebClient
- WebClient.Encoding = System.Text.Encoding.UTF8
- Me.respone = WebClient.DownloadString("https://geocode-maps.yandex.ru/1.x/?format=json&geocode=" + Replace_Adres())
- End Using
- JSONDECODE()
- End Sub
- Private Function Replace_Adres()
- Dim url_adres As String = Replace(adres, " ", "+")
- Return url_adres
- End Function
- Private Sub JSONDECODE()
- Dim MyJson As JObject = Json.JsonConvert.DeserializeObject(respone)
- '[JSON].response.GeoObjectCollection.featureMember.[0].GeoObject.Point.pos
- Coordinates = MyJson("response")("GeoObjectCollection")("featureMember")(0)("GeoObject")("Point")("pos")
- End Sub
- Public Function lat()
- Dim cord As Array = Split(Coordinates, " ")
- Dim l1 As Double = Convert.ToDouble(cord(1))
- Return l1
- End Function
- Public Function lng()
- Dim cord As Array = Split(Coordinates, " ")
- Dim l1 As Double = Convert.ToDouble(cord(0))
- Return l1
- End Function
- End Class
- Sub Main()
- Dim loc As YandexLocatin = New YandexLocatin("4-ый Загородный переулок, дом 20, Минск, Беларусь")
- End Sub
- End Module
|