2014-03-25 82 views
-1

如果我有2個php變量$ latitude和$ longitude,我如何將它們傳遞給url如果緯度12和經度爲15的URL會在圖像url中使用php變量

<img border="0" src="http://maps.googleapis.com/maps/api/staticmap?center=12,15&zoom=16" 

我試過單獨呼應的網址元件,但它似乎沒有工作

回答

2
$lat = 12; 
$long = 15; 
$img = "<img border='0' src='http://maps.googleapis.com/maps/api/staticmap?center=$lat,$long&zoom=16' />" 
echo $img; 

你也可以這樣做:

$img = "<img border='0' src='http://maps.googleapis.com/maps/api/staticmap?center=". $lat. ",". $long."&zoom=16' />" 
+0

您需要在 mesutozer

+0

Or the other way around. – Jonast92

0

這應該工作:

<img border="0" src="http://maps.googleapis.com/maps/api/staticmap?center=<?php echo $latitude; ?>,<?php echo $longitude; ?>&zoom=16" 
1

我不知道你已經嘗試過什麼,但這個會做

$url = "http://maps.googleapis.com/maps/api/staticmap?center=" . $lat . "," . $long ."&zoom=16"; 
Echo $url; 
0

嘗試:

<img border="0" src="http://maps.googleapis.com/maps/api/staticmap?center=<?=$latitude?>,<?=$longitude?>&zoom=16"/> 

<?=$latitude?>,只有很短的回聲,是一樣的做<?php echo $latitude; ?>

http://php.net/manual/en/function.echo.php

+0

Hiya, this may well answer the question... but don't forget that total n00bs will likely somebody come and find this question/answer and will wonder why this works... can you please give some explanation for why/how your solution works? :) –

+0

okay, it's 附近單引號,只是一個短回聲,與<?php echo $ latitude?>相同 – abfurlan

0

使其看起來更簡單。只是迴應整個事情。

<?php 
    $latitude = 12 ; 
    $longitude = 15 ; 

    echo "<img border='0' src='http://maps.googleapis.com/maps/api/staticmap?center=$latitude,$longitude&zoom=16'>" ; 
?>