データ取得ロジックの実装
サンプルアプリで使用するオープンデータは、Microsoft Azure Mobile Service上で動作しているAED検索オープンデータを使用します 。
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Net
Imports System.Runtime.CompilerServices
Imports Newtonsoft.Json
Namespace Models
Public Class AedInfo
Public Property Id As Long
Public Property LocationName As String '/* 場所_地名【名称】*/
Public Property FullAddress As String '/* 住所_住所【住所】*/
Public Property Perfecture As String '/* 構造化住所_都道府県 */
Public Property City As String '/* 構造化住所_市区町村 */
Public Property AddressArea As String '/* 構造化住所_町名 */
Public Property AddressCode As String '/* 住所コード */
Public Property Latitude As Single '/* 緯度経度座標系_緯度 */
Public Property Longitude As Single '/* 緯度経度座標系_経度 */
Public Property FacilityId As String '/* 公共設備_ID */
Public Property FacilityName As String '/* 公共設備_名称 */
Public Property FacilityPlace As String '/* 公共設備_設置場所【設置場所】※受付横とか */
Public Property ScheduleDayType As String '/* 公共設備_利用可能時間【利用可能時間】 */
Public Property PhotoOfAedUrl As String '/* 公共設備_写真URL【写真】 */
Public Property FacilityNote As String '/* 公共設備_補足【補足】 */
Public Property LatLng As Point
End Class
Public Class TCity
Public Property Perfecture As String '/* 構造化住所_都道府県 */
Public Property City As String '/* 構造化住所_市区町村 */
Private _Items = New ObservableCollection(Of AedInfo)
Public Property Items As ObservableCollection(Of AedInfo)
Get
Return Me._Items
End Get
Set(value As ObservableCollection(Of AedInfo))
Me._Items = value
End Set
End Property
End Class
Public Class AedModel
Implements INotifyPropertyChanged
Public Sub New()
End Sub
Private _City = New TCity
Public Property City As TCity
Get
Return Me._City
End Get
Set(value As TCity)
Me._City = value
OnPropertyChanged()
End Set
End Property
Public Async Function SelectData(perfectureName As String, cityName As String) As Task
Dim targetAeds = New ObservableCollection(Of AedInfo)
Try
Dim urlString = String.Format(
"https://aed.azure-mobile.net/api/aedinfo/{0}/{1}/",
perfectureName,
cityName)
Dim request = CType((WebRequest.Create(urlString)), HttpWebRequest)
request.Method = "GET"
request.ContentType = "application/x-www-form-urlencoded"
Try
Dim response = CType((Await request.GetResponseAsync()), HttpWebResponse)
Dim responseDataStream = New System.IO.StreamReader(response.GetResponseStream())
Dim responseResult = responseDataStream.ReadToEnd()
Dim json = JsonConvert.DeserializeObject(Of IEnumerable(Of AedInfo))(responseResult)
Dim aeds = From item In json Order By item.FullAddress
targetAeds = New ObservableCollection(Of AedInfo)
For Each aed In aeds
aed.LatLng = New Point(aed.Longitude, aed.Latitude)
targetAeds.Add(aed)
Next
Catch ex As Exception
OnFaild("NetworkError" + ex.Message)
End Try
Catch ex As Exception
OnFaild("NetworkError" + ex.Message)
Finally
Me.City = New TCity With {.Perfecture = perfectureName,
.City = cityName, .Items = targetAeds}
End Try
End Function
Public Event Faild(sender As Object, e As String)
Protected Sub OnFaild(line As String)
RaiseEvent Faild(Me, line)
End Sub
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(<CallerMemberName> Optional propertyName As String = Nothing)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
End Namespace
