3

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.'&zoom=14&size=700x512&maptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false" />';
    else:
        return '<img src="'.'http://maps.google.com/maps/api/staticmap?center='.$address.'&zoom=14&size=700x512&maptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false" />';
    endif;
}
2
  • What's the function get_post_meta returning? Add var_dump(get_post_meta($post->ID, 'date_address', true)); I have a feeling that it's returning nothing ('' or null) Commented May 24, 2010 at 20:58
  • sorry guys date_address was supposed to be "_date_address" so it was totally unrelated :( Commented May 24, 2010 at 21:04

2 Answers 2

1

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.'&zoom=14&size=700x512&maptype=roadmap&markers=color:blue|label:X|'.$address.'&sensor=false');
    if ($echo) {
        echo '<img src="'.$src.'" />';
    } else {
        return '<img src="'.$src.'" />';
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

the problem was actually unrelated, sorry for buggin' ya, but you get a gold star anyway since you're right...
0

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

'&address=' . $address

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.