繁体   English   中英

从数据库中获取数据并使用它在Google Maps中进行标记

[英]Fetch data from database and use it to make markers in Google Maps

我是Java语言的新手。 我想从MySQL(超过100个)中获取经纬度,并使用它在Google Maps上添加标记。

为此,我认为我必须使用php-服务器端编程。 我能够将数组从PHP传递到Javascript。 这里是

   <?
mysql_connect('localhost', 'username', 'pwd') or die(mysql_error()); 
echo "Connected to MySQL<br />";

mysql_select_db("pro_user") or die(mysql_error());

$result = mysql_query("SELECT * FROM info"); 
$no=count($result);
$i=0;
while($row = mysql_fetch_array( $result ))
{
    $a[$i]=$row['city'];
    $b[$i]=$row['loc_lat'];
    $c[$i]=$row['loc_long'];
    $i++;
}
  ?>
  <html> 
<head> 
    <script type="text/javascript"> 
    function initialize() 
{ 
    var latlng = new google.maps.LatLng(22.3038945, 70.8021599); 
    var myOptions = {
        zoom: 8, 
        center: latlng, 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

<?  for($i=0;$i<count($a); $i++)
    {
        echo "a[$i]='".$a[$i]."';\n";
        echo "b[$i]='".$b[$i]."';\n";
        echo "c[$i]='".$c[$i]."';\n";       

    } 
?>
    function createMarker(latitude,longitude,title) 
    { 
        var markerLatLng = new google.maps.LatLng(latitude,longitude);
        var marker = new google.maps.Marker({ position: markerLatLng, map: map, title: title }); 
    }
    createMarker(22.3038945, 70.8021599,'Gujarat');

for(i=0;i<a.length;i++)
    {   
        document.write(a[i]);
        document.write(b[i]);
        document.write(c[i]);

        initialize().createMarker(b[i], c[i], a[i]);
    }       

} 

    </script>
</head>
<body onload="getData()"></body>
    </html>

现在我被困住了。 我无法通过Javascript数组进行标记。

谷歌地图网站上有一个非常简单的教程,介绍如何使用PHP / XML / MySQL和Javascript ....

http://code.google.com/apis/maps/articles/phpsqlajax.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM