Page 1 of 1

Google Maps -execute code when fully loaded

Posted: Wed May 23, 2012 8:06 am
by HappyFive

hello!

i have a problem with google maps in tiggzi. i managed it to show some additional markers on the map when i press a button.

but now i want to show this markers instantly when the map is loaded. (without pushing the button)

i tried to use "Event" -- "Load" -- "Run Custom JavaScript" -- an the "window.onload" event inside this script -but it still doesn't work.

(i think the basic problem is, that the code (palcing markers) is executed before the map is fully loaded)

thanks for helping me out !


Google Maps -execute code when fully loaded

Posted: Wed May 23, 2012 10:33 am
by Paolo

I have same problem


Google Maps -execute code when fully loaded

Posted: Wed May 23, 2012 3:45 pm
by maxkatz

Can you post the code you are trying to run?


Google Maps -execute code when fully loaded

Posted: Wed May 23, 2012 5:26 pm
by HappyFive

as mentioned before:
this code is unter event "load" -- "run custom javascript" --

Code: Select all

updateMap();

and there is a own script implementing this function
(i deleted some comments -i hope i didn't destroy anything ;-) )

function called via button -- works fine
function called on "load" event -- doesn't show anything

Code: Select all

 
 function updateMap() 
 { 

 var map = Tiggr("karte").gmap; 
 google.maps.event.addListenerOnce(map, 'Load', function(){ 
     //@Max Katz: IS NEVER SHOWN ! 
     alert("map fully loaded"); 
 }); 

 var myLatlng = new google.maps.LatLng(36.11179,-115.174724); 

 var image = new google.maps.MarkerImage('[url=http://dl.dropbox.com/u/13141539/lift-3d-neu-klein.png']http://dl.dropbox.com/u/13141539/lift...[/url], 
       new google.maps.Size(50, 50), 
       new google.maps.Point(0,0), 
       new google.maps.Point(25, 25)); 

   var shadow = new google.maps.MarkerImage('[url=http://dl.dropbox.com/u/13141539/lift-3d-neu-klein_schatten.png']http://dl.dropbox.com/u/13141539/lift...[/url], 
   new google.maps.Size(50, 100), 
   new google.maps.Point(0,0), 
   new google.maps.Point(25, 25)); 

   var shape = { 
       coord: [1, 1, 1, 50, 50, 50, 50 , 1], 
       type: 'poly' 
   }; 

   //add marker 
   var marker = new google.maps.Marker({ 
         icon: image, 
         shape: shape, 
         shadow: shadow, 
         position: myLatlng, 
         title:"Testmarker" 
    }); 

//clicklistener 
google.maps.event.addListener(marker, 'click', function()  
{ 
 localStorage.setItem('1', 36.11179,-115.174724); 
 });   

   marker.setMap(map);   
}

thx!


Google Maps -execute code when fully loaded

Posted: Thu May 24, 2012 3:56 pm
by maxkatz

This code should work:

code
var myLatlng = new google.maps.LatLng(36.11179,-115.174724);

var marker = new google.maps.Marker({
position: myLatlng,
title:"Testmarker"
});

//clicklistener
google.maps.event.addListener(marker,'click', function()
{ console.log("You click on the marker");
});

Tiggr("googlemap1").options.mapElement.gmap('addMarker',marker);
Tiggr("googlemap1").options.mapElement.gmap("refresh");
/code