-1

I'm using data from a JSON file and PHP, which includes a 'location' array that contains lat and long values.

I echoed the values out like this :

foreach ($row['location'] as $result) {
    echo 'Latitude:', '<br>', $result['lat'], '<br>';
    echo 'Longtitude:', '<br>', $result['long'];
}

I'm trying to make it so that there is a Google Map on the page showing the location that you can click and will take you to the maps page.

 <iframe 
  width="300" 
  height="170" 
  frameborder="0" 
  scrolling="no" 
  marginheight="0" 
  marginwidth="0" 
  src="https://maps.google.com/maps?q= <?php echo $result['lat']  , $result['long']?> &hl=en-GB&z=14&amp;output=embed"
 >

This opens Google Maps and everything, but does not put a comma between the two values, so Maps says it's not a correct location. I can't figure out how to add the comma so that it works fine. Hope that I explained this well enough, any help would be fab, thanks.

kmoser
  • 8,780
  • 3
  • 24
  • 40
renumi
  • 7
  • 1

1 Answers1

-1

Simple concatenation within your PHP script will do the trick:

<iframe
    width="300"
    height="170"
    frameborder="0"
    scrolling="no"
    marginheight="0"
    marginwidth="0"
    src="https://maps.google.com/maps?q=<?php echo $result['lat'].','.$result['long'];?>&hl=en-GB&z=14&amp;output=embed"
/>

Using comma within echo simply concatenates both variables, i.e. it works like dot, so won't appear as a string between them.

mitkosoft
  • 5,262
  • 1
  • 13
  • 31