Full Library · cf4f005534 - SVN.BY: Go Git Service
Browse Source

Full Library

British Petrolium 7 years ago
parent
commit
cf4f005534
3 changed files with 54 additions and 3 deletions
  1. 5 0
      SimpleYandexLocation.vbproj
  2. 45 3
      YandexLocation.vb
  3. 4 0
      packages.config

+ 5 - 0
SimpleYandexLocation.vbproj

@@ -47,6 +47,10 @@
47 47
     <OptionInfer>On</OptionInfer>
48 48
   </PropertyGroup>
49 49
   <ItemGroup>
50
+    <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
51
+      <HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
52
+      <Private>True</Private>
53
+    </Reference>
50 54
     <Reference Include="System" />
51 55
     <Reference Include="System.Data" />
52 56
     <Reference Include="System.Deployment" />
@@ -104,6 +108,7 @@
104 108
       <LastGenOutput>Settings.Designer.vb</LastGenOutput>
105 109
     </None>
106 110
     <None Include="App.config" />
111
+    <None Include="packages.config" />
107 112
   </ItemGroup>
108 113
   <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
109 114
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 45 - 3
YandexLocation.vb

@@ -1,7 +1,49 @@
1
-Module YandexLocation
1
+Imports System.Net
2
+Imports Newtonsoft
3
+Imports Newtonsoft.Json.Linq
2 4
 
3
-    Sub Main()
5
+Module YandexLocation
4 6
 
5
-    End Sub
7
+    Public Class YandexLocatin
8
+
9
+        Dim adres As String
10
+        Dim respone As String
11
+        Dim Coordinates As String
12
+
13
+        Sub New(adres As String)
14
+            Me.adres = adres
15
+            Using WebClient = New WebClient
16
+                WebClient.Encoding = System.Text.Encoding.UTF8
17
+                Me.respone = WebClient.DownloadString("https://geocode-maps.yandex.ru/1.x/?format=json&geocode=" + Replace_Adres())
18
+            End Using
19
+            JSONDECODE()
20
+        End Sub
21
+
22
+        Private Function Replace_Adres()
23
+            Dim url_adres As String = Replace(adres, " ", "+")
24
+            Return url_adres
25
+        End Function
26
+        Private Sub JSONDECODE()
27
+            Dim MyJson As JObject = Json.JsonConvert.DeserializeObject(respone)
28
+            '[JSON].response.GeoObjectCollection.featureMember.[0].GeoObject.Point.pos
29
+            Coordinates = MyJson("response")("GeoObjectCollection")("featureMember")(0)("GeoObject")("Point")("pos")
30
+        End Sub
6 31
 
32
+        Public Function lat()
33
+            Dim cord As Array = Split(Coordinates, " ")
34
+            Dim l1 As Double = Convert.ToDouble(cord(1))
35
+            Return l1
36
+        End Function
37
+
38
+        Public Function lng()
39
+            Dim cord As Array = Split(Coordinates, " ")
40
+            Dim l1 As Double = Convert.ToDouble(cord(0))
41
+            Return l1
42
+        End Function
43
+    End Class
44
+
45
+
46
+    Sub Main()
47
+        Dim loc As YandexLocatin = New YandexLocatin("4-ый Загородный переулок, дом 20, Минск, Беларусь")
48
+    End Sub
7 49
 End Module

+ 4 - 0
packages.config

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<packages>
3
+  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
4
+</packages>