views:

79

answers:

2

I'm trying to get the following code to output an IMG tag with the URL for Google Static Maps API http://code.google.com/apis/maps/documentation/staticmaps/#Imagesizes embedded in there... the result is that everything except the $address is being output successfully... what am I doing wrong?

function event_map_img($echo = true){
    global $post;
    $address = get_post_meta($post->ID, 'date_address', true);
    if($echo): echo '<img src="'.'http://maps.google.com/maps/api/staticmap?center='.$address.'&amp;zoom=14&amp;size=700x512&amp;maptype=roadmap&amp;markers=color:blue|label:X|'.$address.'&amp;sensor=false" />';
    else:
        return '<img src="'.'http://maps.google.com/maps/api/staticmap?center='.$address.'&amp;zoom=14&amp;size=700x512&amp;maptype=roadmap&amp;markers=color:blue|label:X|'.$address.'&amp;sensor=false" />';
    endif;
}
A: 

Try this:

function event_map_img($echo = true) {
    global $post;
    $address = urlencode(get_post_meta($post->ID, 'date_address', true));
    $src = htmlspecialchars('http://maps.google.com/maps/api/staticmap?center='.$address.'&amp;zoom=14&amp;size=700x512&amp;maptype=roadmap&amp;markers=color:blue|label:X|'.$address.'&amp;sensor=false');
    if ($echo) {
        echo '<img src="'.$src.'" />';
    } else {
        return '<img src="'.$src.'" />';
    }
}
Gumbo
the problem was actually unrelated, sorry for buggin' ya, but you get a gold star anyway since you're right...
Brian
A: 

I think you are missing the & separator for $address after blue|label:X|, it should be like:

'&address=' . $address
Web Logic