Required plugins for this example: MBS MacFrameworks Plugin, MBS Main Plugin, MBS MacBase Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/CoreLocation/Locate Address Web
Class App Inherits WebApplication
EventHandler Sub Opening(args() as String)
t = new CoreLocationEventsTimer
End EventHandler
Property t As CoreLocationEventsTimer
End Class
Class MyCLGeocodeCompletionHandlerMBS Inherits CLGeocodeCompletionHandlerMBS
EventHandler Sub Completed(geocoder as CLGeocoderMBS, placemarks() as CLPlacemarkMBS, error as NSErrorMBS, tag as variant)
dim w as new WebSessionContext(targetSession)
dim l as WebListBox = List
l.RemoveAllRows
if error<>nil then
l.AddRow "Error", error.LocalizedDescription
end if
l.AddRow "Count of placemarks", str(UBound(placemarks)+1)
for each p as CLPlacemarkMBS in placemarks
l.AddRow "name", p.name
l.AddRow "locality", p.locality
l.AddRow "subLocality", p.subLocality
l.AddRow "thoroughfare", p.thoroughfare
l.AddRow "subThoroughfare", p.subThoroughfare
l.AddRow "administrativeArea", p.administrativeArea
l.AddRow "subAdministrativeArea", p.subAdministrativeArea
l.AddRow "postalCode", p.postalCode
l.AddRow "country", p.country
dim ad as Dictionary = p.addressDictionary
for each key as Variant in ad.keys
dim value as Variant = ad.Value(key)
if value.IsArray then
// convert array of variants with strings to string array for join
dim v() as Variant = value
dim s() as string
for each k as Variant in v
s.Append k.StringValue
next
value = Join(s, ", ")
end if
l.AddRow "Address "+key, value
next
l.AddRow "areasOfInterest", join(p.areasOfInterest, ", ")
l.AddRow "ocean", p.ocean
l.AddRow "inlandWater", p.inlandWater
l.AddRow "ISOcountryCode", p.ISOcountryCode
dim r as CLRegionMBS = p.region
if r<>nil then
l.AddRow "region latitude", str(r.latitude)
l.AddRow "region longitude", str(r.longitude)
l.AddRow "region radius", str(r.radius)
end if
dim cl as CLLocationMBS = p.location
l.AddRow "Location Latitude", str(cl.Latitude)
l.AddRow "Location Longitude", str(cl.Longitude)
next
Finally
// clearnup
selfRef = nil
list = nil
targetSession = nil
End EventHandler
Property list As WebListBox
Property selfRef As MyCLGeocodeCompletionHandlerMBS
Property targetSession As WebSession
End Class
Class CoreLocationEventsTimer Inherits Timer
EventHandler Sub Action()
// for web app, check every few Milliseconds if something happend
CLLocationManagerMBS.CheckEvents
End EventHandler
Sub Constructor()
mode = 2
Period = 500
End Sub
End Class