I have some code that uses browser.setText(myScript) to load a page in to the browser widget. The script has a small page with one <div> and the necessary code to init the google maps api. I then want to call a js function to set the location (setLocation below).
This works if I do the 2 things in 2 separate actions with a couple of seconds between, but if I try to run them in the same action, it doesn't work. I have tries using the addProgressListener() but the page load seems to finish without the scripts being dowloaded and run. I have alse tried a Thread.sleep(5000), but nothing seems to help?
<!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 4.01//EN">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Airport view with google maps</title>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var map;
function setLocation(lat, long) {
var latlng = new google.maps.LatLng(lat, long);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.SATELLITE,
disableDefaultUI: false
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
</script>
<style type="text/css">
*, html { margin:0; padding:0 }
div#map_canvas { width:100%; height:100%; }
}
</style>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>