I am trying to get the following code to output an IMG tag with the Google Static Maps API URL http://code.google.com/apis/maps/documentation/staticmaps/#Imagesizes built in there ... the result is that everything except $ address succeeds ... 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; }
Try the following:
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.'" />'; } }
I think you are missing a separator &for $addressafter blue|label:X|, it should look like this:
&
$address
blue|label:X|
'&address=' . $address
Source: https://habr.com/ru/post/1746911/More articles:Migrate an ASP.NET application to the cloud - asp.netHow can I quickly try out a large number of regular expressions and find out which one matches? - regexAssociationTypeMismatch with expected type in nested model forms - ruby | fooobar.comLinq with a long clause where - c #Bad method names and what it says about code structure - methodsHow to create this array? (PHP) - arraysASP.NET MVC 2: Mechanics behind the order / order line in the editing form - asp.net-mvcHow to save service settings by installing InstallShield update - installerСимвол "Ctypes" не найден "для динамической библиотеки в OSX - c++Python file sharing site - pythonAll Articles