Page 1 of 1

create new marker on map widget

Posted: Fri May 11, 2018 9:11 pm
by okk
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

Re: create new marker on map widget

Posted: Fri May 11, 2018 10:37 pm
by okk
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

Re: create new marker on map widget

Posted: Fri May 11, 2018 11:11 pm
by okk
+ a bonus question: can I place a livecode object like a button on top of a map widget??? thx. o

Re: create new marker on map widget

Posted: Fri Jun 29, 2018 4:22 pm
by mturney
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

Re: create new marker on map widget

Posted: Thu Aug 09, 2018 11:18 am
by okk
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

Re: create new marker on map widget

Posted: Thu Aug 09, 2018 11:20 am
by okk
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

Re: create new marker on map widget

Posted: Thu Aug 09, 2018 5:46 pm
by Klaus
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

Re: create new marker on map widget

Posted: Thu Aug 23, 2018 8:38 pm
by okk
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

Re: create new marker on map widget

Posted: Thu Dec 27, 2018 4:35 pm
by okk
Hi all, my original issue is still unresolved, according to Panos answer to my bug report https://quality.livecode.com/show_bug.cgi?id=21584 the Android behaviour is actually the one that is correct. That means, my work-around is likely not to be working in future updates. Therefore I would like to repeat my original question: Does anyone of you have a suggestion how can a user of my app create a new map marker by clicking and holding on the map widget ?
Thanks for any hints!
Oliver

Re: create new marker on map widget

Posted: Thu May 28, 2020 5:05 am
by paddysox
Can anyone please confirm the map widget to be working on Android, by using livecode latest stable release? It meets my requirements well for the ios but shows an empty map on simulator and Samsung Galaxy Note8. Initially the app would crash without the valid/correct google API keys (used Map API not the other keys to resolve it). Now the app is stable but no maps on drawn in the map widget?

Thanks for all the help in advance.

Pradeep

Re: create new marker on map widget

Posted: Thu Aug 04, 2022 9:05 am
by TorstenHolmer
Thanks okk,

great idea, works perfect in IDE :-)

This save me a lot of time!

Cheers,
Torsten

Re: create new marker on map widget

Posted: Tue Aug 09, 2022 3:04 pm
by okk
Hi Torsten,
glad that the workaround was useful. Do you have any ideas on how to get this functionality working on mobile? Best. Oliver

Re: create new marker on map widget

Posted: Sat May 06, 2023 9:51 pm
by JereMiami
Okk,

Did you get it to work on mobile?

Regards
J,