从Mysql查询获取数据到javascript

时间:2014-11-25 19:52:43

标签: javascript json

我有带有该查询的文件index.php

$link = mysql_query("SELECT * FROM waypoints WHERE id = 1 "); //ORDER BY date
$items = array();
while($row = mysql_fetch_array($link)){
//$items[] = array('Id' => $row['id'],'Latitude' => $row['latitude'], 'Longitude' => $row['longitude'], 'Date' => $row['date'], 'hora' => 'hour');

    json_encode(array('Id' => $row['id'],'Latitude' => $row['latitude'], 'Longitude' => $row['longitude'], 'Data' => $row['date'], 'hora' => 'hour'));
            }

所以我想使用文件map.js上的json_encode值作为变量。我想将json值用于startaddress和finishaddress变量

map.js内容:

var map;
var directionsDisplay;

google.maps.DirectionsRenderer     var directionsService = new google.maps.DirectionsService();

function initialize() {
   directionsDisplay = new google.maps.DirectionsRenderer(); 
   var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);

   var options = {
      zoom: 5,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };

   map = new google.maps.Map(document.getElementById("map"), options);
   directionsDisplay.setMap(map);
}

initialize();


$("form").submit(function(event) {


    event.preventDefault();

   var startaddress = $("#txtstartaddress").val();
   var finishaddress = $("#txtfinishaddress").val();

   var request = { 
      origin: startaddress, 
      destination: finishaddress, 
      waypoints: [{location: 'Rodoviária, Campinas'}, {location: 'Taquaral, Campinas'}],
        travelMode: google.maps.TravelMode.DRIVING 
   };

   directionsService.route(request, function(result, status) {
      if (status == google.maps.DirectionsStatus.OK) {
         directionsDisplay.setDirections(result); 
      }
   });
});

0 个答案:

没有答案