Simple Icon unexpected T_STRING using single quote, but Marker not showing with single quote

38 views
Skip to first unread message

Pigeon

unread,
Jul 16, 2010, 3:32:38 AM7/16/10
to Google Maps JavaScript API v3
For some reason I'm getting an unexpected T_STRING when using single
quote in var image ='image'; so I changed it to double quote but now I
don't get a marker...

var image = "pp_logo.png";
var myLatLng = new google.maps.LatLng(51.51440469156112,
-0.1354837417602539);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Pink Pigeon",
icon: image

What am I doing wrong?

http://www.pinkpigeon.net/contact/

Thank you

Will

Pil

unread,
Jul 16, 2010, 4:13:08 AM7/16/10
to Google Maps JavaScript API v3
The image doesn't exist within your defined path.

Caution! Calling this address crashed my browser

http://www.pinkpigeon.net/contact/pp_logo.png


Instead the image seems to be here

http://www.pinkpigeon.net/pp_logo.png

Pigeon

unread,
Jul 16, 2010, 7:44:32 AM7/16/10
to Google Maps JavaScript API v3
Thank you, I think I fixed it but I am now getting a new error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /
home/purplepenguin/cranihum.com/wp-content/themes/kava/functions.php
on line 67

this is line 67 </div>';

here's my code snippet from functions.php:

<?php
function wpmap() {
return '<script type="text/javascript" src="http://maps.google.com/
maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(51.51440469156112,
-0.1354837417602539);
var myOptions = {
zoom: 16,
center: latlng,
navigationControl: true,
navigationControlOptions: {style:
google.maps.NavigationControlStyle.DEFAULT},
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: true
};
var map = new
google.maps.Map(document.getElementById("map_canvas"), myOptions);

var image = '/wp-content/themes/kava/images/pp_logo.png';
var myLatLng = new google.maps.LatLng(51.51440469156112,
-0.1354837417602539);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Pink Pigeon",
icon: image
});
}
window.onload = initialize;
</script>
<div id="mapsize">
<div id="map_canvas" style="width:100%; height:100%">
</div>
</div>';
}
add_shortcode('map', 'wpmap');
?>

I must have missed something...

Thanks

Will

Pigeon

unread,
Jul 16, 2010, 8:12:30 AM7/16/10
to Google Maps JavaScript API v3
got it to work :-)

changed back to double quotes around the image path, I guess using
single quotes must have caused a problem with the WordPress shortcode
function?

thank you for the help

Will

Rossko

unread,
Jul 16, 2010, 9:10:24 AM7/16/10
to Google Maps JavaScript API v3
> changed back to double quotes around the image path, I guess using
> single quotes must have caused a problem with the WordPress shortcode
> function?

No, its basic php syntax.

You have written a php function that boils down to
function wpmap() {
return 'some enormous long string';
}

If you try
return 'some enormous 'long' string';
php will break because it can't guess that the ' at long is not the
end of the intended string, and then it doesn't know what to do with
the rest of the text left over.

Not a maps or javascript issue.

Pigeon

unread,
Jul 16, 2010, 10:24:25 AM7/16/10
to Google Maps JavaScript API v3
Thank you for the explanation.

I decided to tidy everything up a bit. I made a separate js file for
the javascript http://www.pinkpigeon.net/wp-content/themes/kava/js/map.js

and then made my WordPress shortcode only the divs:

function wpmap() {
return '<div id="map_canvas" style="width:632px; height:323px;
margin-left:40px">
</div>';
}
add_shortcode('map', 'wpmap');

It's easier to see what's going on this way.

It works really well, I'm very happy, I only started looking at this
just over a day ago and now I have a google map that loads really
fast, a custom marker, a "home" button, street view pegman and a
dropdown menu. I've achieved much more than I could have done with any
wordpress plugin, it's neater, I learnt more because I did all myself,
and I wrote my first wordpress shortcode to boot!

Thank you for the help and useful documentation for the API :-)
Reply all
Reply to author
Forward
0 new messages