Hi,
I need to make a jquery app for school, now i got stuck with loading some variables out of the database for google maps. Its a table where fuelpump info is stored. But i need to get the coordinates (stored too) out of the database for each pump to find them on google maps. Im trying to for 2 weeks now and i hope that someone knows how to do it. Thanks for helping me
Below is a big part of the code:
- <script>
var db;
//------------------ Opdracht 2a - Zoek de fout in deze code
$(document).ready(function()
{
//Maak een nieuwe database aan
try
{
if (!window.openDatabase) {
alert('Not Supported -> Please try with a WebKit Browser');
} else {
//nieuw , in volgende stuk is de create databse vervangen door opendb ipv create, dit gebeurt automatisch
db = openDatabase('pompjes2', '1.0', 'brommix pompen', 3072*1024);
}
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS pomp (id uniqe, naam, adres, afstand, prijs, coordh, coordb);');
// Dit stond eerst in een regel met create databse met create with tabel, dit werkt niet
});
//einde nieuw
}
catch(e)
{
console.log(e);
}
pompWeergeven();
});
//--------------------- Opdracht 2a Zoek de fout in de code hierboven
//--------------------- Opdracht 2b - Vul de code aan
function pompToevoegen(){
var pompje = $('input:text[name=pompnaam]').val();
var adresje = $('input:text[name=adres]').val();
var coordhtje = $('input:text[name=coordh]').val();
var coordbtje = $('input:text[name=coordb]').val();
var afstandje = $('input:text[name=afstand]').val();
var prijsje = $('input:text[name=prijs]').val()
//Vul hier de code in die een star met ranking invult in de tabel star
db.transaction(function(tx){
tx.executeSql("INSERT INTO pomp (id, naam, adres, afstand, prijs, coordh, coordb) VALUES (NULL, ?, ?, ?, ?, ?, ?)", [pompje,adresje,afstandje,prijsje,coordhtje,coordbtje]); // Voegt de ingevoerde waardes toe aan database
});
console.log("pompje "+ pompje +" met adres "+ adresje +" toegevoegd aan de databaseje");
pompWeergeven();
}
//---------------------- Einde opdracht 2b
function pompWeergeven(){
console.log("Pompjes in database weergeven");
db.transaction(function(tx){
tx.executeSql('SELECT * FROM pomp ORDER BY afstand', [], function (tx, results) {
var len = results.rows.length, i;
if(len > 0){
$('#pompentabel').replaceWith('<table id="pompentabel"><tr><th>Pomp</th><th>Adres</th><th><a href=#home>Afstand</a></th><th><a href=#home>Prijs</a></th></tr></table>');
$('#pompentabel').hide();
for(var i = 0; i< len; i++){
$('#pompentabel tr:last').after('<tr><td><a href=#kaartoverzicht onclick=laadcoord>'+results.rows.item(i).naam+'</a></td><td>'+results.rows.item(i).adres+'</td><td>'+results.rows.item(i).afstand+'</td><td>'+results.rows.item(i).prijs+'</td></tr>');
var identieficatie = results.rows.item(i).id;
}
$('#pompentabel').show('slow');
}
}, null);
});
}
function laadcoord() {
db.transaction(function(tx){
tx.executeSql('SELECT * FROM pomp WHERE ', [], function (tx, results) {
var bcoordinaat = coordb
var hcoordinaat = coordh
});
}
function initialize() {
// Hier wordt de map aangemaakt en de oude afbeelding ingeladen
var map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(bcoordinaat,hcoordinaat),
zoom: 18,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
});
}
</script>