Reformulating the question .. I have a MySQL database, inside it contains a table named map, inside the map table I have the fields idmapa (auto_increment), lat (which stores the latitude of a map position), lng ( which stores the length of a map position), detail (which stores the details that the user can insert, referring to the position of the map) and image (which stores only the name of the image referring to the position of the map). The ajax script below sends the data I want to save in the database to a php file. Within the php file, I have an if, which will receive the data sent by ajax in order to save in the database within the map table the respective data according to the fields of the database quoted above.
What I want to do: I need to do the reverse process, ie, request the map table data to the php, using ajax in the request, but after requests, I want to save this data in specific vectors, so that later I can create a loop to add this data to a markup on the map. NOTE: I'm using Google Maps API Javascript.
PHP saving in the bank
if($_GET['acao']=='btn_finaliza'){
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
$detalhe = $_GET['detalhe'];
$imagem = $_GET['imagem'];
$SQL = "INSERT INTO mapa (lat, lng, detalhe, imagem) VALUES ('$latitude','$longitude','$detalhe','$imagem')";
$re = mysql_query($SQL, $serve)or die(mysql_error());
echo $SQL;
}
Ajax script that sends the data to php
$.ajax({
type: "get",
url: $server+"/conecta.php",
data: "latitude="+$tlati+"&longitude="+$tlong+"&detalhe="+$detalhe+"&imagem="+$imagem+"&acao=btn_finaliza",
success: function(data) {
location.href='#page_mapa';
navigator.notification.alert('Problema cadastrado', '', 'ok');}
});
After evaluating the tips, I'm trying this way:
PHP:
if($_GET['acao']== 'marcacao'){
$SQL = "SELECT * FROM mapa";
$resultados = mysql_query($sql)or die (mysql_error());
$res=mysql_fetch_array($resultados);
if ($linha = @mysql_num_rows($resultados) == 0){
echo 0;
}
else{
echo $linha['lat'];
echo $linha['lng'];
exit;
}
}
Java Script and Ajax:
function marcacao(){
$.ajax({
type: "get",
url: $server+"/conecta.php",
data: 'acao=marcacao',
success: function(data) {
// le o retorn de data, que já será um array/vetor, e popula seu mapa com API do Google Maps
var map = new google.maps.Map(
document.getElementById("map"),
{
center : new google.maps.LatLng($lat, $lng),
zoom : 5,
mapTypeId : google.maps.MapTypeId.ROADMAP
}
);
var image = 'images/ray.png';
var marker = new google.maps.Marker(
{
title : "VOCÊ ESTÁ AQUI: "+$lat+", "+$lng,
position : new google.maps.LatLng($lat, $lng),
map: map,
icon: image
});
marker.setMap(map);
}
});
}
However, I think the way I'm passing the php variables to javascript (echo $ line ["lat"] and echo $ line ["lng"]]) are wrong, so the markings on the map do not are being made.