0

I have a database of locations that includes the street address as well as latitude and longitude. I want to display a map based on the lat/long on each location's page. This is what I have, which I know doesn't work:

How can I get the shortcodes to output their HTML so that they can be used in an instance like this?

I've tried a couple variations of code, which I have pieced together from different threads, but none of the answers fit my exact request. Ex:

<?php
$shortcode = do_shortcode('[ASL_STORE field="long"]');
$content = '. $longitude .';
return $content;
?>
<?php
$shortcode = do_shortcode('[ASL_STORE field="lat"]');
$content = '. $latitude .';
return $content;
?>
<iframe width="300" height="220" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed/v1/streetview?key=myapikey&location='$latitude',$'longitude'&heading=210&pitch=10&fov=35" >
 </iframe>
0

1 Answer 1

0

Make sure that

  • you do not assign all the shortcodes to the same $shortcode variable because then you will override previous values and lose them
  • you properly initialize $latitude and $longitude
  • you do not return when you do not need to
<?php
$longitude = do_shortcode('[ASL_STORE field="long"]');
$latitude = do_shortcode('[ASL_STORE field="lat"]');
?>
<iframe width="300" height="220" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps/embed/v1/streetview?key=myapikey&location='<?php echo $latitude; ?>','<?php echo $longitude; ?>'&heading=210&pitch=10&fov=35" >
 </iframe>
Sign up to request clarification or add additional context in comments.

4 Comments

I'm using wordpress, and for whatever reason, the PHP script is not processing first. What am I doing wrong?
@AnyaCurry why do you think that and what is being executed before?
When I use the coding above, the output is still <iframe width="300" height="220" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="google.com/maps/embed/v1/… echo $latitude; ?>','<?php echo $longitude; ?>'&heading=210&pitch=10&fov=35" > </iframe> The page doesn't seem to recognize the php output to use in the iframe. I didn't know if this was because it's wordpress? Is there some other way I should implement it?
@AnyaCurry what is the name of the file where you have this iframe displayed?

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.