Google地图未显示正确的位置

时间:2013-12-13 08:12:43

标签: php google-maps

我正在尝试创建一个简单的PHP代码,当用户点击体育场的链接时,它将使用谷歌地图显示体育场的位置。但是,当我尝试点击体育场时,它没有显示确切的位置。我已多次检查代码,我不知道问题出在哪里。

这是地图的代码

<html>
<?php

session_start();
include('dbconn.php');

$id=$_GET['id'];

$sql=mysql_query("SELECT stadium, city, state FROM fixtures where fixtures_id='" .$id ."'");

$row= mysql_fetch_array($sql);

    $stadium = urlencode($row['stadium']);
    $city = urlencode($row['city']);
    $state = urlencode($row['state']);
    $place = "$city,+$stadium,+$state";
?>


<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" 
marginwidth="0" src="https://maps.google.com/maps?     
f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=<?php echo $place; ?>
&amp;aq=0&amp;ie=UTF8&amp;hq=&amp;hnear=<?php echo $place; ?>
&amp;t=m&amp;iwloc=&amp;output=embed"></iframe>

</html>

这就是我将体育场,城市和州存储在数据库中的方式 enter image description here

这是输出不正确的

enter image description here

2 个答案:

答案 0 :(得分:2)

在数据库中存储经度和纬度信息会更容易,这样您就可以确保显示正确的体育场。

如果您添加国家/地区名称和地点而非地点,有时地理编码的效果会更好。根据用户的位置,只使用这个地方可能会出现严重错误...

答案 1 :(得分:0)

尝试存储lat和long

这里尝试制作有效的地址字符串

 $place = "$stadium,+$city,+$state";