Working with MKMapView (OSX 10.9+, PB 5.40+ x64)

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Working with MKMapView (OSX 10.9+, PB 5.40+ x64)

Post by wilbert »

Simple example

Code: Select all

; *** MKMapView example ***

; OSX Requirements : OSX 10.9+
; PB Requirements  : PB 5.40+ x64


; *** Constants and structures ***

Enumeration
  #MKMapTypeStandard
  #MKMapTypeSatellite
  #MKMapTypeHybrid
EndEnumeration

Structure CLLocationCoordinate2D
  latitude.d
  longitude.d
EndStructure

Structure MKCoordinateSpan
  latitudeDelta.d
  longitudeDelta.d
EndStructure

Structure MKCoordinateRegion
  center.CLLocationCoordinate2D
  span.MKCoordinateSpan
EndStructure


; *** MapKit framework check *** 

If Not dlopen_("/Library/Frameworks/MapKit.framework/MapKit", #RTLD_LAZY)
  MessageRequester("Error", PeekS(dlerror_(), -1, #PB_UTF8))
  End
EndIf


; *** MapGadget procedures ***

Procedure MapGadget(Gadget, x, y, Width, Height, Flags = 0)
  Protected Result, ContainerID, Viewer, Frame.NSRect
  Result = ContainerGadget(Gadget, x, y, Width, Height, Flags)
  CloseGadgetList()
  If Gadget = #PB_Any
    ContainerID = GadgetID(Result)
  Else
    ContainerID = GadgetID(Gadget)
  EndIf
  Viewer = CocoaMessage(0, CocoaMessage(0, 0, "MKMapView alloc"), "initWithFrame:@", @Frame)
  CocoaMessage(0, ContainerID, "setContentView:", Viewer)
  CocoaMessage(0, Viewer, "release")
  ProcedureReturn Result
EndProcedure

Procedure MapGadgetView(MapGadget)
  ProcedureReturn CocoaMessage(0, GadgetID(MapGadget), "contentView")  
EndProcedure



; *** Example *** 

Define Region.MKCoordinateRegion
Define View.i

If OpenWindow(0, 0, 0, 400, 400, "MapGadget example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  MapGadget(0, 10, 10, 380, 380, #PB_Container_Flat)
  View = MapGadgetView(0)
  
  Region\center\latitude = 48.49
  Region\center\longitude = 7.69
  Region\span\latitudeDelta = 0.08
  Region\span\longitudeDelta = 0.08
  
  CocoaMessage(0, View, "setMapType:", #MKMapTypeHybrid)
  CocoaMessage(0, View, "setRegion:@", @Region, "animated:", #YES)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
mk-soft
Always Here
Always Here
Posts: 5401
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Working with MKMapView (OSX 10.9+, PB 5.40+ x64)

Post by mk-soft »

Very good. Thanks :D
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply