我有一个数据库驱动的网站,它获取地址和地址显示在谷歌地图上。这里是包含谷歌地图嵌入的字符串。我不知道地点的纬度,但我知道地址和地区。地点没有出现。
<?php $add = $row_rsDoc['Address'];
$address = str_replace(" ","+",$add);
$gtown = str_replace(" ","+",$row_rsDoc['Town']);
$gprov = str_replace(" ","+",$row_rsDoc['Province']);
$googlestr=$address.','.'+'.$gtown.','.'+'.$gprov;
echo $googlestr;
?>
<th width="446" class="entry" scope="col"><iframe width="441" height="243" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.za/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo $googlestr; ?>&aq=&sll=-26.178375,28.033719&ie=UTF8&hq=&hnear=&radius=15000&t=m&output=embed"></iframe><br />
用urlencode()
代替str_replace()
(参见urlencode()文档)
此外,如果你在URL中包含位置坐标,请尝试使用:
<th width="446" class="entry" scope="col"><iframe width="441" height="243" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.za/maps?f=q&source=s_q&hl=en&geocode=&q=<?php echo $googlestr; ?>&aq=&ie=UTF8&output=embed"></iframe><br />
您需要对您的地址进行地理编码以获得长/晚,然后使用标记和覆盖将标记嵌入到您的谷歌地图上。有一个很好的例子如何做到这一点在谷歌地图文档如何应用静态标记和如何地理编码。
过程是这样的。
On address add -> request geocode -> store return long/lat into db -> On map load通过ajax回调到php页面返回你的long/lat数组标记在地图上
这正是我怎么做的,它最大限度地减少了实际查询的数量,你必须对谷歌api做,因为它的请求有限的免费用户。如果你想要实际的代码请告诉我,我可以从我的一个应用中复制粘贴出来它就是这么做的