PHP与最近的街道Google API对齐

时间:2013-03-10 00:02:55

标签: php javascript google-maps

我正在使用带有GOOGLE API的JavaScript,它可以通过点击手动将点捕捉到最近的街道。取自(http://econym.org.uk/gmap/snap.htm

的示例

我有一个坐标数据库,我想通过这个东西,点到最近的街道点,我正在使用PHP,但我不能让mysql PHP变量与javascript“交谈”。

我希望它几乎接近实时,读取URL变量将它们添加到数据库然后让它在Google地图上将其捕捉到

我可以从URL变量手动执行此操作,但是我无法通过javascript GoogleAPI捕捉到道路功能来获取PHP和数据库坐标

//Fetching from your database table.
            $query = "SELECT DISTINCT * FROM $usertable";
            $result = mysql_query($query);

            if ($result) {
                while($row = mysql_fetch_array($result)) {
                    $name = $row["$latitude_db"];
                    $name1 = $row["$longitude_db"];


  echo "var dirn = new google.maps.DirectionsService();";
  echo "var map;";
echo "
  function initialize() {
    var center = new google.maps.LatLng(40.04, -79.23);
    var myOptions = {
      zoom:10,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: center
    }
    ";
    echo "map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);";

    echo "var urllat = getUrlVars()['lat'];";

    echo "var urllong = getUrlVars()['long'];";



    echo "var combo = new google.maps.LatLng('$name', '$name1');";
    echo "alert($name1);";





    echo "var request = {";
            echo "origin: combo,";
            echo "destination: combo,";
            echo "travelMode: google.maps.DirectionsTravelMode.DRIVING";
        echo "};";
        echo "dirn.route(request, function(response, status) {";
          echo "if (status == google.maps.DirectionsStatus.OK) {";
               echo " if(response.routes && response.routes.length > 0){";
                   echo " route = response.routes[0];";
                   echo " if(route.overview_path && route.overview_path.length > 0)";
            echo "{";

                        echo "pos = route.overview_path[0];";


                            echo "new google.maps.Marker({";
                                echo "position: pos,";
                                echo "map: map";
                            echo "});";



                    echo "}";
                echo "}";
          echo "}";
        echo "});";

    echo "}";



                }
            }




}            

echo "</script>";

此代码将在循环或页面加载...

0 个答案:

没有答案