我有代码:
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=266%20Orms%20St%20Providence%20RI&key=mykey" allowfullscreen> </iframe>' ;
我想在 q = 之后将变量$ street传递到网址,例如:
src="https://www.google.com/maps/embed/v1/place?q=$street&key=mykey
地图正在显示,但$ street的实际街道未被识别。此外,我如何传递多于1个变量?我尝试过$ street和$ city,不成功:
src="https://www.google.com/maps/embed/v1/place?q=$street+city&key=mykey
答案 0 :(得分:2)
您使用单引号,因此需要进行连接:
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=' . urlencode($street) . '" allowfullscreen> </iframe>';
答案 1 :(得分:0)
你也可以试试这个。
echo '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q='.$street.'" allowfullscreen> </iframe>';