Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/MapKit/MapKit Custom Image


Required plugins for this example: MBS MacBase Plugin, MBS MacFrameworks Plugin, MBS MacCocoa 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 Custom Image

This example is the version from Thu, 18th Sep 2019.

Project "MapKit Custom Image.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() #if TargetMachO and Target64Bit then // okay #else MsgBox "Please run on macOS in 64-bit." #endif End EventHandler
End Class
Class MainWindow Inherits Window
Control Map Inherits MapKitViewControlMBS
ControlInstance Map Inherits MapKitViewControlMBS
EventHandler Sub Open() Self.mapview = Me.View End EventHandler
EventHandler Function viewForAnnotation(mapView as MKMapViewMBS, annotation as MKAnnotationMBS) As MKAnnotationViewMBS For Each pin As MKPointAnnotation In pins If pin = annotation Then // found Dim view As New MKAnnotationViewMBS(annotation, "test") view.draggable = False view.image = icon views.Append view return view End If Next Break // not found? End EventHandler
End Control
EventHandler Sub Open() GetXojoIcon mapview.showsUserLocation = True Add "Austin, USA" // 2006, 2007, 2008, 2015 Add "Orlando, USA" // 2012, 2013 Add "Las Vegas, USA" // 2014 Add "Houston, USA" // 2016 Add "Denver, USA" // 2018 Add "Miami, USA" // 2019 Add "Nashville, USA" // 2020 End EventHandler
Sub Add(address as string) // find the address via geocoder Dim c As New CLGeocoderMBS Dim h As New CLGeocodeCompletionHandlerMBS AddHandler h.Completed, AddressOf geocodeAddressStringCompleted dim tag as Variant c.geocodeAddressString(address, h, tag) geocoders.Append c End Sub
Sub GetXojoIcon() // find Xojo app and take the icon Dim runningApplications() As NSRunningApplicationMBS = NSRunningApplicationMBS.runningApplicationsWithBundleIdentifier("com.xojo.xojo") If runningApplications.Ubound >= 0 Then Dim runningApplication As NSRunningApplicationMBS = runningApplications(0) Dim url As String = runningApplication.BundleURL Dim file As New FolderItem(url, FolderItem.PathTypeURL) icon = NSWorkspaceMBS.iconForFile(file) icon.setSize 32, 32 Else Break // xojo not running End If End Sub
Sub geocodeAddressStringCompleted(handler as CLGeocodeCompletionHandlerMBS, geocoder as CLGeocoderMBS, placemarks() as CLPlacemarkMBS, error as NSErrorMBS, tag as variant) // we got something, so show on map If placemarks.Ubound >= 0 Then Dim placemark As CLPlacemarkMBS = placemarks(0) Dim location As CLLocationMBS = placemark.location Dim pin As New MKPointAnnotation pin.placemark = placemark pin.coordinate = New CLLocationCoordinate2DMBS(location.Latitude, location.Longitude) pin.title = placemark.name pins.Append pin mapView.addAnnotation pin Else Break End If End Sub
Note "Plugins needed"
MacFrameworks Main MacCocoa MacBase MacControls
Property geocoders() As CLGeocoderMBS
Property icon As NSImageMBS
Property mapview As MKMapViewMBS
Property pins() As MKPointAnnotation
Property renderers() As Variant
Property reverseGeocoder As CLGeocoderMBS
Property views() As MKAnnotationViewMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Module Module1
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
End Module
Class MKPointAnnotation Inherits MKPointAnnotationMBS
Property placemark As CLPlacemarkMBS
End Class
End Project

See also:

The items on this page are in the following plugins: MBS MacFrameworks Plugin.


The biggest plugin in space...