create new marker on map widget

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

create new marker on map widget

Post by okk » Fri May 11, 2018 9:11 pm

Hi, I am trying to use the new Map Widget in Livecode Indy 9.0.0. I would like to create a new marker on the map when the user clicks on the map widget for a second (mousedown without moving the mouse). The widget seems not to create any mousedown message, so I thought I need to have an invisible button on top of the map widget, but then I loose the native map navigation (scroll, zoom etc.). Any hints how to solve this? Thanks. Oliver

okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Fri May 11, 2018 10:37 pm

Hi, I perhaps found a workable solution, see the atttached stack. I placed an invisible button on top of the map widget with follwoing code:

Code: Select all



on mousedown
   local repeatcounter
   put the mouseloc into tempmouseloc
   repeat while the mouse is down
      wait 2 ticks
      if the mouseloc is not tempmouseloc then pass mousedown
      put repeatcounter+1 into repeatcounter
      if repeatcounter > 10 then 
         
         set the rect of me to the rect of widget "utopia"
         put the left of me into xmini
         put the width of me into xmaxi
         put the top of me into ymini
         put the height of me into ymaxi
         
         put the region of widget "utopia" into tempregion
         set the itemDelimiter to comma
         
         
         put item 1 of tempregion into latcenter 
         put item 2 of tempregion into loncenter
         put item 3 of tempregion into latspan
         put item 4 of tempregion into lonspan
         put latcenter + latspan/2 into latmini
         put loncenter - lonspan/2 into lonmini
         put latcenter - latspan/2 into latmaxi
         put loncenter + lonspan/2 into lonmaxi
         
         put latmaxi-latmini into latdiff
         put lonmaxi-lonmini into londiff
         
         put the mouseh into xposition
         put the mousev into yposition
         
         put (latmini+(yposition-ymini)/ymaxi*latdiff) into currentlat
         put (lonmini+(xposition-xmini)/xmaxi*londiff) into currentlon
         ask "name of the marker"
         if the result is "Cancel" then exit mousedown
         
         put the markers of widget "utopia" into tMarkers
         put currentlat & comma & currentlon into tMarkers [it]["coordinates"]
         put it into tMarkers[it]["title"]
         set the markers of widget "utopia" to tMarkers
         
         exit repeat
      end if
   end repeat
end mousedown
Do you think this is the way to go or are there easier solutions? Thanks. Oliver
Attachments
mapmarkers.livecode.zip
(1.67 KiB) Downloaded 30 times

okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Fri May 11, 2018 11:11 pm

+ a bonus question: can I place a livecode object like a button on top of a map widget??? thx. o

mturney
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Mon May 09, 2011 3:01 pm

Re: create new marker on map widget

Post by mturney » Fri Jun 29, 2018 4:22 pm

Thank you for the information on the map widget, OKK. Does anyone know how to have the map go to the My location when the map opens? I know I can set the showsUserLocation, but how do I have the map go to the location of the user when the map opens. I can't seem to find that parameter. Thanks!
matt

okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Thu Aug 09, 2018 11:18 am

Hi Matt,
I could not find a way to center the map around the user position using just the properties of the map widget. A work-around could be to read the current location from the gps sensor and then set the region of your map widget with current readings of latitude and longitude as centre coordinates. Look "mobileCurrentLocation" in the dictionary if you are not familiar with gps tracking.

Best
Oliver

okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Thu Aug 09, 2018 11:20 am

Btw. my method posted above works fine on MacOS and iOS standalones, but I could not get it working on Android devices. So any help with this issue in regards to Android deployment is highly welcome.

Best
Oliver

Klaus
Posts: 10381
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: create new marker on map widget

Post by Klaus » Thu Aug 09, 2018 5:46 pm

Hi Oliver,

did you read the last paragraph of this page "Deploying on Android":
https://livecode.com/docs/9-0-0/components/map-widget/
Looks like you need to supply an Google Maps API key!


Best

Klaus

okk
Posts: 86
Joined: Wed Feb 04, 2015 11:37 am

Re: create new marker on map widget

Post by okk » Thu Aug 23, 2018 8:38 pm

Hi Klaus, I have the google API keys entered in the inclusions tab of the standalone settings. I get the map widget itself working, but I can't fetch the extended mousedown message which should trigger the creation of a new marker. It works on desktop but not on the device. The script I posted is located in an invisible button above the map-widget. It seems that in the android standalone this invisible button is placed below the map-widget and I can't fetch any mousedown message.

Best
OLiver

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”