Я пытаюсь создать линию поли на картах Google, но сначала получаю данные в моей БД.а затем к моему файлу php и к моему файлу сценария.следующее, как я генерирую свои данные json в моем DBPHPfile .. извините, если это немного грязно
while($row = pg_fetch_assoc($result)){
$cleaned = clean($row['longlat']);
$count =true;
$temp = 0;
$temp2 = 0;
for($x = 0; $x <= strlen($cleaned)-1; $x++){
if($cleaned[$x] == ' '){
$temp2 = $x - $temp;
if($count == true){
array_push($long, remove_spaces(substr($cleaned, $temp, $temp2)));
$count = false;
}
else{
$count = true;
array_push($lat, remove_spaces(substr($cleaned, $temp, $temp2)));
}
$temp = $x;
}
}
$temp2 = strlen($cleaned) - $temp;
array_push($lat, substr($cleaned, $temp, $temp2+1));
}
$finalroutes = array();
// finalizing my routes
for($x = 0; $x<sizeof($long);$x++){
$long[$x]=remove_spaces($long[$x]);
settype($long[$x], "float");
$lat[$x]=remove_spaces($lat[$x]);
settype($lat[$x], "float");
array_push($finalroutes, "{lat: $lat[$x], lng: $long[$x]}");
}
echo json_encode($finalroutes);
, тогда мой сценарий это
$(function(){
$('#go').click(function(){
var longtemp = $('#long').val();
var lattemp = $('#lat').val();
$.ajax({
url:"dbphp.php",
method:"POST",
data:{longtemp:longtemp, lattemp:lattemp},
success:function(data){
map = new google.maps.Map(document.getElementById('map'), {zoom: 18, center: {lat: 8.264670, lng: 124.263394}, mapTypeId: 'terrain'});
flightPlanCoordinates = JSON.parse(data); //from here
// var newflights=[];
// for(var i = 0; i <flightPlanCoordinates.type.length();i++)
// newflights[i]=flightPlanCoordinates[i];
console.log(data);
flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});//to here
flightPath.setMap(map);
}
})
})
})
я отметил, где проблема такэто легко найти.