markers in google maps?

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
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

markers in google maps?

Post by link76 » Wed Dec 12, 2012 11:14 am

I would like to insert markers in google maps, how to do?

Code: Select all

on mouseUp
   --get revBrowserOpen(the windowId of this stack, "http://maps.google.it/maps?near=piazza+duomo+milano&hl=it&t=m&z=13&output=embed") 
   get revBrowserOpen(the windowId of this stack, "http://maps.google.it/maps?q=milano&hl=it&t=m&z=13&iwloc=near&output=embed") 
   
   if it is an integer then
      put it into tBrowserId
      revBrowserSet tBrowserId, "rect", the rect of image "browser"
      revBrowserSet tBrowserId, "showborder","true"
      --
   else
      answer "There was an error: " && it  --if the browser doesn't start, show the error. 
   end if
end mouseUp
thank you

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: markers in google maps?

Post by bangkok » Wed Dec 12, 2012 5:02 pm

But if you need dynamic map (with zoom etc.) then I see only one solution :
-livecode generates the html page with all javascript inside (along with your dynamic data)
-and then open this local file with your browser :

Code: Select all

   launch url "file:"&tPath&"/map.html"

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: markers in google maps?

Post by link76 » Thu Dec 13, 2012 8:25 am

bangkok wrote:
But if you need dynamic map (with zoom etc.) then I see only one solution :
-livecode generates the html page with all javascript inside (along with your dynamic data)
-and then open this local file with your browser :

Code: Select all

   launch url "file:"&tPath&"/map.html"
how to create html page with live code ?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: markers in google maps?

Post by bangkok » Thu Dec 13, 2012 9:29 am

link76 wrote: how to create html page with live code ?
It's very easy.

-take a standard html page (with javascript) that manages the creation of a google map and the creation of markers
-remove the variable parts, replaced them with special "tags"
-then in LiveCode your script will "fill in" this script with data (by replacing the tags)
-save the file and initiate the command launch

Here is the "core" html page i use. You'll notice the 2 tags [DATA1] [DATA2]

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>PC Pro - Google Maps Simple Example</title>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>	
	<script type="text/javascript">
		$(document).ready(function () {
			// Define the latitude and longitude positions
[DATA1]

			// Set up options for the Google map
			var myOptions = {
			zoom: 6,
				center: latlngPos1,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			// Define the map
			map = new google.maps.Map(document.getElementById("map"), myOptions);
			// Add the marker
[DATA2]

		});
	</script>
</head>
<body>
	<div id="map" style="width:800px;height:800px;margin-top:10px;"></div>
</body>
</html>

And here my script :

Code: Select all

put fld "coreScript" into lamorce

   put empty into lesData1 
   put empty into lesData2

   set itemdelimiter to tab

--- here my data, name of the marker and geocode of the marker, one per line

   repeat with i = 1 to the number of lines of aTraiter
      
      put item 1 of line i of atraiter into leNom
      put item 2 of line i of atraiter into lesCoordonnees
      
      put "var latlngPos"&i&" = new google.maps.LatLng("&lesCoordonnees&");"&cr after lesData1
      
      put "var marker = new google.maps.Marker({"&cr after lesData2
      put "position: latlngPos"&i&","&cr after lesData2
      put " map: map,"&cr after lesData2
      put "title: "&quote&leNom&quote&"});"&cr after lesData2
      
   end repeat
   
---we replace the tags with our data

   replace "[DATA1]" with lesData1 in lamorce
   replace "[DATA2]" with lesData2 in lamorce

--then save the file as a html file, and launch into browser

   put the effective filename of this stack into tPath
   set the itemDelimiter to slash
   delete last item of tPath
   put "file:"&tPath&"/map.html" into myFile
   put lamorce into url myFile
   launch url "file:"&tPath&"/map.html"

To help you, I attach a html file generated by my script (with 3 markers).
Attachments
map.zip
(824 Bytes) Downloaded 523 times

archer2009BUSknbj
Posts: 72
Joined: Sat Apr 06, 2013 8:09 am
Location: London

Re: markers in google maps?

Post by archer2009BUSknbj » Sat Apr 20, 2013 2:54 pm

I'm looking to embed a Google Map into an App I'm creating for Android - I just downloaded the map.html file and it ran perfectly in my windows 7 web browser

But what I don't know how to do is create a box in LiveCode that displays the map, and also is there a way to make it so if a person clicks on the marker with their finger it takes them to a certain Card in LiveCode

What I want is for the markers to represent people, and when you click on the marker it takes you to that person's profile page which is a Card in LiveCode

I did try working through a lesson I found on the RunRev website that is supposed to display the KickStarter website but it didn't work for me on my windows PC and wouldn't allow me to create an APK File for Android

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: markers in google maps?

Post by Subas » Thu Jun 20, 2013 1:09 am

dear Bangkok.

wanted your advice on this topic. If I have a set of gps position in a text file (long/lat) any idea how can I read this text file in real-time to update Google map based on your example? those log/lat will then put the marks based on this text file.

regards

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: markers in google maps?

Post by bangkok » Thu Jun 20, 2013 7:40 am

Hello,

Good idea to refresh this thread (Google Map API has changed).

So here is a stack to :
-type an address
-get the geocode from google map
-and then create the map (local html with javascript file, sent to your browser)
Attachments
MAP.zip
(2.08 KiB) Downloaded 521 times

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: markers in google maps?

Post by Subas » Sat Jun 22, 2013 7:29 am

Dear Bangkok.

Thank you for the stack. I will test it out and request for advice if I am not sure how to use it.

Best regards
Subas

Ray Tham
Posts: 3
Joined: Sun Apr 27, 2014 1:17 am

Re: markers in google maps?

Post by Ray Tham » Tue May 06, 2014 3:26 am

Hi Bangkok,

Just downloaded your Map.Zip file and tried to run it, its fails to do anything. The Lat & lat fields come up blank and so cannot create a map. Any idea what's happening?

Thanks .. Ray

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: markers in google maps?

Post by bangkok » Tue May 06, 2014 7:02 am

Ray Tham wrote: Just downloaded your Map.Zip file and tried to run it, its fails to do anything. The Lat & lat fields come up blank and so cannot create a map. Any idea what's happening?
Download the new version here (posted on april 29) :

http://forums.runrev.com/download/file.php?id=3548

http://forums.runrev.com/viewtopic.php? ... 74#p102422

genie
Posts: 108
Joined: Thu Dec 01, 2011 7:19 am

Re: markers in google maps?

Post by genie » Wed Sep 24, 2014 2:41 am

Hello Bangkok,

Thank you for the stack. One question... how to I handle when a marker in the HTML is clicked? Is it possible that the stack goes to another card when a particular marker is clicked?


Thanks,
Genie

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”