Google Maps probleem
ik heb een website met allemaal 112-meldingen. Nu wil ik deze meldingen met Google Maps tonen (als extraatje op de website).
Ik krijg alleen de adressen er niet goed in.
var addresses = ["adres1 plaats1", "adres2 plaats2"]; gaat goed, maar niet via het ophalen van de adressen uit de database.
Iemand een idee wat ik fout doe??
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps: archiefmeldingen 112nwv.nl</title>
<script src=" http://maps.google.com/?file=api&v=2.x&key=<?php echo $key; ?>"
type="text/javascript"></script>
<style type="text/css">
body {
font-family: Verdana, Arial, sans serif;
font-size: 11px;
margin: 2px;
}
table.directions th {
background-color:#EEEEEE;
}
img {
color: #000000;
}
</style>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
//var addresses = ["adres1 plaats1", "adres2 plaats2"];
var addresses = <?php
$sql="
SELECT adres , plaats
FROM meldingen
ORDER BY datumtijd DESC";
if($result = mysql_query($query)){
$adresses = '[';
while($row = mysql_fetch_assoc($result)){
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
?>;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections(addresses, "nl_NL");
}
}
function setDirections(addresses, locale) {
str = "from: ";
for(i = 0; i < addresses.length; i++)
{
if(i == 0)
{
str = str + addresses[i] + " "
}else{
str = str + " to: " + addresses[i] + " "
}
}
gdir.load(str,
{ "locale": locale });
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
function onGDirectionsLoad(){
// Use this function to access information about the latest load()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<h2>Google maps route</h2>
Ik lever zelf de adressen aan in een javascript array!
<br/>
<table class="directions">
<tr><th>Route</th><th>Kaart</th></tr>
<tr>
<td valign="top"><div id="directions" style="width: 275px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>
</tr>
</table>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps: archiefmeldingen 112nwv.nl</title>
<script src=" http://maps.google.com/?file=api&v=2.x&key=<?php echo $key; ?>"
type="text/javascript"></script>
<style type="text/css">
body {
font-family: Verdana, Arial, sans serif;
font-size: 11px;
margin: 2px;
}
table.directions th {
background-color:#EEEEEE;
}
img {
color: #000000;
}
</style>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
//var addresses = ["adres1 plaats1", "adres2 plaats2"];
var addresses = <?php
$sql="
SELECT adres , plaats
FROM meldingen
ORDER BY datumtijd DESC";
if($result = mysql_query($query)){
$adresses = '[';
while($row = mysql_fetch_assoc($result)){
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
?>;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections(addresses, "nl_NL");
}
}
function setDirections(addresses, locale) {
str = "from: ";
for(i = 0; i < addresses.length; i++)
{
if(i == 0)
{
str = str + addresses[i] + " "
}else{
str = str + " to: " + addresses[i] + " "
}
}
gdir.load(str,
{ "locale": locale });
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
function onGDirectionsLoad(){
// Use this function to access information about the latest load()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<h2>Google maps route</h2>
Ik lever zelf de adressen aan in een javascript array!
<br/>
<table class="directions">
<tr><th>Route</th><th>Kaart</th></tr>
<tr>
<td valign="top"><div id="directions" style="width: 275px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td>
</tr>
</table>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Herbert Foppen
als ik trouwens helemaal onderaan (rond rg 111) een echo doe van $addresses, dan is deze helemaal leeg!
Bouw eens een foutafhandeling in na je query om te kijken of dit allemaal wel netjes gelukt is?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var addresses = <?php
$sql = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
echo $addresses; // Dit ben je vergeten
?>;
$sql = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
echo $addresses; // Dit ben je vergeten
?>;
$sql is wat anders dan $query... Dat wordt geen succes!
pgFrank schreef op 29.12.2008 13:12:
$sql is wat anders dan $query... Dat wordt geen succes!
idd stomme fout, maar daarmee wordt het niet opgelost
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var addresses = <?php
$query = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
echo $addresses;
?>;
$query = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses = ']';
}
echo $addresses;
?>;
Je mist een echo
Op regel 43 staat $adresses = ']'; dat moet volgens mij $adresses .= ']'; zijn.
Ook is het handiger/verstandiger om je logica voor je output te plaatsen.
Dus eerst je gehele php en dan op de plek waar het moet komen alleen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
var addresses = <?php
$query = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses .= ']';
}
?>;
$query = "SELECT adres, plaats FROM meldingen ORDER BY datumtijd DESC";
if($result = mysql_query($query))
{
$adresses = '[';
while($row = mysql_fetch_assoc($result))
{
$adresses .= '"'.$row['adres']. ' ' .$row['plaats'].'"';
}
$adresses .= ']';
}
?>;
en iets verder naar beneden:
Hoe staat verder je error_reporting en display_errors?
TJVB schreef op 29.12.2008 13:48:
Hoe staat verder je error_reporting en display_errors?
ini_set('display_errors', 1);
error_reporting(E_ALL);
Ik denk dat er een typfoutje zat bij de laatste echo...dubbel d moest het zijn. Nu worden wel alle adressen getoond, maar ik denk dat er lege tussen zitten en dat hij daar niet helemaal lekker mee overweg kan ;). Ga ff wat dingen opschonen...