Php 谷歌地图中的方向链接

Php 谷歌地图中的方向链接,php,wordpress,google-maps,curl,Php,Wordpress,Google Maps,Curl,我正在尝试将谷歌地图集成到我的WordPress项目中。我确实有用户的地址,我并没有使用任何WordPress插件,我使用PHP和curl来显示我的谷歌地图和标记以及所有其他选项 代码: <?php if(isset($_POST['show'])) { $iframe_width = '400px'; $iframe_height = '400px'; $address = $_POST['address']; //$address = '12215

我正在尝试将谷歌地图集成到我的WordPress项目中。我确实有用户的地址,我并没有使用任何WordPress插件,我使用PHP和curl来显示我的谷歌地图和标记以及所有其他选项

代码:

<?php
if(isset($_POST['show']))
{
    $iframe_width = '400px'; 
    $iframe_height = '400px'; 
    $address = $_POST['address'];

    //$address = '12215 East Sprague Avenue, Spokane Valley, WA 99206'; 

    //echo 'Address to find: ' . $address . '<br>'; 

    $address = urlencode($address); 
    $url = "http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false";
    //echo 'URL: ' . $url . '<br>';

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HEADER,0); 
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $data = curl_exec($ch); 
    curl_close($ch); 

    $geo_json = json_decode($data, true); 

    if ($geo_json['status'] == 'OK') { 

        $latitude = $geo_json['results']['geometry']['location']['lat']; 
        $longitude = $geo_json['results']['geometry']['location']['lng'];

        $map_params = array(
            'f' => 'q',
            'source' => 's_q',
            'hl' => 'en', 
            'q' => $address,
            'aq' => 0,
            'ie' => 'UTF8',
            'hnear' => $address,
            't' => 'm',
            'll' => $longitude .','. $latitude, 
            'z' => 12,
            'output' => 'embed'
        );

        $url = 'http://maps.google.com/maps?' . http_build_query($map_params);
    ?> 

    <iframe width="<?php echo $iframe_width; ?>" height="<?php echo $iframe_height; ?>" frameborder="0" 
    scrolling="no" marginheight="0" marginwidth="0" src="<?php echo $url ?>"></iframe> 

    <?php 

    } else {
        echo "<p>No Address Available</p>";
    } 
}
else
{
?>
<form action="#" method="post">
<table align="center">
    <tr>
        <td align="right">
            Enter Address : 
        </td>
        <td>
            <input type="text" style="width:500px;" name="address">
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="hidden" name="show" value="true">
            <input type="submit" name="map" value="Show MAP">
        </td>
    </tr>
</table>
</form>
<?php } ?> 


这很奇怪,但如果您只是将iframe宽度从
400px
增加到
660px
,它将显示地图上的方向按钮

旁注:只要在结果数组
0
键中

$latitude  = $geo_json['results'][0]['geometry']['location']['lat']; 
$longitude = $geo_json['results'][0]['geometry']['location']['lng'];

嘿,谢谢Rikesh.一旦我增加了iframe的宽度,它现在就可以完美工作了。