All, I've got the following code:
<script type="text/javascript">
function Store( lat, long, text )
{
this.latitude = lat;
this.longitude = long;
this.html = text;
}
var myStores = [<?php echo $jsData;?>, null];
addLoadEvent(loadMap);
This is populated with the following code:
$lat = $post->latitude;
$long = $post->longitude;
$post_id = $post->ID;
$get_post_info = get_post($post_id);
$name = $get_post_info->post_title;
$jsData = $jsData . "new Store( $lat, $long, '$name' ),\n";
My page loads fine without the javascript portion. However when I add the javascript I get the following error:
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; MS-RTC LM 8; AskTbAD2/5.14.1.20007) Timestamp: Wed, 22 Feb 2012 16:45:35 UTC Message: Arg: Illegal input string in Vector2D Line: 68 Char: 63 Code: 0 URI: http://localhost/wordpress/wp-content/themes/parallelus-mingle/assets/css/PIE.htc
I actually narrowed it down even further and this line is the one causing the error:
addLoadEvent(loadMap);
Here is the complete code for the addLoadEvent(loadMap):
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function'){
window.onload = func
} else {
window.onload = function() {
oldonload();
func();
}
}
}
var map,
infowin=new google.maps.InfoWindow({content:'moin'});
function loadMap()
{
map = new google.maps.Map(
document.getElementById('map'),
{
zoom: 12,
mapTypeId:google.maps.MapTypeId.ROADMAP,
center:new google.maps.LatLng(<?php echo $_SESSION['pav_event_latitude']; ?>,
<?php echo $_SESSION['pav_event_longitude']; ?>)
});
addPoints(myStores);
}
function addPoints( points )
{
var bounds=new google.maps.LatLngBounds();
for ( var p = 0; p < points.length; ++p )
{
var pointData = points[p];
if ( pointData == null ) {map.fitBounds(bounds);return; }
var point = new google.maps.LatLng( pointData.latitude, pointData.longitude );
bounds.union(new google.maps.LatLngBounds(point));
createMarker( point, pointData.html );
}
map.fitBounds(bounds);
}
var number = 2; // or whatever you want to do here
function createMarker(point, popuphtml)
{
var popuphtml = "<div id=\"popup\">" + popuphtml + "<\/div>";
var marker = new google.maps.Marker(
{
position:point,
map:map,
icon:'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld='+number+'|FF776B|000000',
shadow:'https://chart.googleapis.com/chart?chst=d_map_pin_shadow'
}
);
google.maps.event.addListener(marker, 'click', function() {
infowin.setContent(popuphtml)
infowin.open(map,marker);
});
}
</script>
Any ideas why that would cause an error?
It appears that your addLoadEvent()
isn't working as it should, and is sending your empty argument list for loadMap()
to the PIE.htc onload event method. Also, I believe the typeof
of a function will actually return object
not function
. Either way, try dropping this in place of your function:
function addLoadEvent(func) {
if (window.addEventListener) {
window.addEventListener('load', func, false);
} else if(window.attachEvent) {
window.attachEvent('onload', func);
}
}
Another option, which would ensure that it works in all browsers, would be to use jQuery's $(document).ready()
, domReady, or some other equivalent.
Edit: Also, this line:
var myStores = [<?php echo $jsData;?>, null];
will end up with two commas before the null
, unless you left out some PHP code in your original question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With