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: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
okk
Posts: 176
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: 176
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 315 times

okk
Posts: 176
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: 15
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: 176
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: 176
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: 13806
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: 176
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

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

Re: create new marker on map widget

Post by okk » Thu Dec 27, 2018 4:35 pm

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

paddysox
Posts: 2
Joined: Thu May 28, 2020 4:49 am

Re: create new marker on map widget

Post by paddysox » Thu May 28, 2020 5:05 am

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

TorstenHolmer
Posts: 57
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: create new marker on map widget

Post by TorstenHolmer » Thu Aug 04, 2022 9:05 am

Thanks okk,

great idea, works perfect in IDE :-)

This save me a lot of time!

Cheers,
Torsten

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

Re: create new marker on map widget

Post by okk » Tue Aug 09, 2022 3:04 pm

Hi Torsten,
glad that the workaround was useful. Do you have any ideas on how to get this functionality working on mobile? Best. Oliver

JereMiami
Posts: 119
Joined: Mon Nov 03, 2014 12:17 am

Re: create new marker on map widget

Post by JereMiami » Sat May 06, 2023 9:51 pm

Okk,

Did you get it to work on mobile?

Regards
J,

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”