iOS Map Directions with MergMK

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
williamsc84
Posts: 7
Joined: Sun Aug 06, 2017 1:54 pm

iOS Map Directions with MergMK

Post by williamsc84 » Thu Aug 31, 2017 6:46 pm

I am using Livecode Indy and with that i get the MergMK extension.

I found a sample stack online that I now have working that is showing perfectly a map on my screen with my current location. Here is the bulk of the code in that sample stack.

Code: Select all

on openCard
   ## MAP MergMK Stuff
   if environment() = "mobile" then
      /* So the screen does not go dim */
      mobileLockIdleTimer
      /* Start to get the location of your iphone/iPad */
      mobileStartTrackingSensor "location", false
      checkLocation
   end if
   if environment() = "mobile" then
      send "createMap" to this card in 100 millisecs
   end if
end openCard

on locationChanged latitude, longitude
   /* keep the location in a custom prop */
   set the theCurrentLocation of this stack to latitude & comma & longitude
end locationChanged

on checkLocation
   /* Wait until the iPhone has got your latitude/Longitude */
   repeat forever
      wait 0 millisecs with messages
      if the theCurrentLocation of this stack is not empty then
         
         exit repeat
      end if
   end repeat
end checkLocation

on createMap
   mergMKCreate
   mergMKSet "rect", the rect of grc "map"
   mergMKSet "center coordinate", the theCurrentLocation of this stack, true
   mergMKSet "user tracking mode", "follow"
   mergMKSet "shows user location", true
   mergMKSet "zoom enabled",true
   mergMKSet "scroll enabled",true
   mergMKSet "map type", "standard"
   mergMKSet "region", "150,150" ,false
   mergMKSet "visible",true
end createMap

on closeCard
   if environment() = "mobile" then
      mobileLockIdleTimer
   end if
   if environment() = "mobile" then
      mergMKDelete
   end if
end closeCard
However what I am actually wanting to achieve is that when the map opens up it shows directions to either 1 or 2 locations.

Within my app I know the lat & long of the users current location, I know the lat and long of 2 nearby locations.

I would like to display directions on this map to either 1 but preferably 2 locations.

I have been looking at

Code: Select all

mergMKGetDirections
and

Code: Select all

mergMKdirections
but I am just not quite understanding what I have to do. I have searched around for some sample code on this but I haven't been able to track it down.

Any information that may help me become unstuck would be super appreciated.

Many Thanks

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”