Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/MapKit/MapKit Route
Required plugins for this example: MBS MacBase Plugin, MBS MacFrameworks Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/MapKit/MapKit Route
This example is the version from Sat, 1st Nov 2019.
Project "MapKit Route.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer)
dim item as Variant = me.RowTag(row)
if item isa MKRouteMBS then
dim route as MKRouteMBS = item
dim steps() as MKRouteStepMBS = route.steps
for each RouteStep as MKRouteStepMBS in steps
dim a as string = RouteStep.notice
if a.len > 0 then
a = " ("+a+")"
end if
List.AddRow RouteStep.instructions+a
next
end if
End EventHandler
End Control
EventHandler Sub Open()
// you can use Map Items for current location, local search results or generate some
// take some coordinates
dim c1 as new CLLocationCoordinate2DMBS(52.518611, 13.408333) // Berlin
dim c2 as new CLLocationCoordinate2DMBS(48.137222, 11.575556) // Munich
dim p1 as new MKPlacemarkMBS(c1)
dim p2 as new MKPlacemarkMBS(c2)
dim i1 as new MKMapItemMBS(p1)
dim i2 as new MKMapItemMBS(p2)
dim request as new MKDirectionsRequestMBS
request.transportType = request.TransportTypeAutomobile
request.source = i1
request.destination = i2
request.requestsAlternateRoutes = true
Directions = new MKDirections(request)
Directions.list = list
Directions.calculateDirections
End EventHandler
Property Directions As MKDirections
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MKDirections Inherits MKDirectionsMBS
EventHandler Sub calculateDirectionsCompleted(response as MKDirectionsResponseMBS, error as NSErrorMBS, tag as Variant)
list.DeleteAllRows
if error <> nil then
MsgBox error.LocalizedDescription
end if
if response <> nil then
dim routes() as MKRouteMBS = response.routes
for each route as MKRouteMBS in routes
dim a as string = join(route.advisoryNotices, ", ")
if a.len > 0 then
a = " ("+a+")"
end if
list.AddFolder route.name+" with "+str(route.expectedTravelTime/60)+" minutes"+a
list.RowTag(list.LastIndex) = route
next
end if
End EventHandler
Property list As listbox
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacFrameworks Plugin.