【问题标题】:Use google map api marker in php mysql website在 php mysql 网站中使用 google map api 标记
【发布时间】:2014-06-22 04:32:35
【问题描述】:

我目前正在建立一个网站,其中有一个功能允许用户在谷歌地图中标记他们的家庭地址,并使用 php+mysql 将坐标存储在数据库中,然后在另一个页面上从 db 中获取坐标并用来显示。我该怎么做?

我对google map api不是很熟悉,所以如果你们中的任何人都可以提供类似的示例代码,那将是很大的帮助:)

【问题讨论】:

  • Google 提供了大量示例。您为什么不尝试他们的基本功能,然后根据您的需要修改/调整更复杂的功能?
  • 你试过什么?你要存储什么信息。一旦检索到它们,似乎不仅应该存储地址,还应该存储纬度和经度值。
  • 嗯,这很简单:您将事件处理程序附加到地图上放置标记的 onclick 事件,并将其坐标存储在变量中。当用户单击保存时,您最好通过 AJAX 将变量发送到服务器。这个例子应该让你走上正轨:google-developers.appspot.com/maps/documentation/javascript/… 不过,你必须自己弄清楚 AJAX 部分。尝试为此研究 jQuery。

标签: php mysql api google-maps


【解决方案1】:

据我了解,您遇到了想要从数据库中获取数据并根据经纬度显示位置的地图的部分。如果这是正确的,您可以试试这个..

基于此链接https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=es#createtable上的示例

这是对我有用的代码(我不知道是否有多余的东西)。

<?php
    //select statement that grabs latitude and longitude for the current user and stores them to   variables eg $lat and $lng. Then you just echo them below into the javascript.
?>
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">

    var map;
    var geocoder;
    function InitializeMap() {

    var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php $lng; ?>);
    var myOptions =
    {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDefaultUI: true
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
}

window.onload = InitializeMap;

</script>
</head>
<body>

<table>

<tr>
<td colspan ="2">
<div id ="map" style="height: 253px;width: 447px;" >
</div>
</td>
</tr>
</table>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 2015-06-10
    • 2012-03-30
    • 2023-03-11
    • 2014-05-01
    • 1970-01-01
    相关资源
    最近更新 更多