0

私は現在、ユーザーがGoogleマップで自宅の住所をマークできる機能があり、座標がphp + mysqlを使用してデータベースに保存されるWebサイトを構築しています。別のページでは、座標がdbから取得され、表示に使用されます. それ、どうやったら出来るの ?

私はGoogleマップAPIにあまり詳しくないので、同様のサンプルコードを提供していただけると大変助かります:)

4

1 に答える 1

2

私が理解しているように、データベースからデータを取得し、緯度と経度に基づいて位置を示す地図を提示する部分で行き詰まってしまった..これが正しい場合は、これを試すことができます..

このリンクにある例に基づいて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>
于 2014-06-21T20:32:35.037 に答える