I have the file index.php with that query
$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'));
}
so I want use the json_encode values on file map.js as variables. I want use the json values into startaddress and finishaddress variables
the map.js content:
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);
}
});
});