inzoemen google maps
dit is mijn js en xml script dat ik heb om de markers te laten zien
js:
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
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
//load Google Map
//<![CDATA[
var iconBlue = new GIcon();
iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);
var iconRed = new GIcon();
iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);
var customIcons = [];
customIcons["restaurant"] = iconBlue;
customIcons["bar"] = iconRed;
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
//map.addControl(new GSmallMapControl()); // inuitzoemen enkel met + -
map.addControl(new GLargeMapControl()); // in uit zoemen met + - en lijn er tussen
map.addControl(new GMapTypeControl());
// op het punt waar gecentreerd, hoogt en sateliet + kaard standaard
map.setCenter(new GLatLng(50.84064, 4.38354), 7, G_HYBRID_MAP);
GDownloadUrl("googlemaps/googlexml2.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var Plaatsnaam = markers[i].getAttribute("Plaatsnaam");
var Straat = markers[i].getAttribute("Straat");
var Nr = markers[i].getAttribute("Nr");
var Postcode = markers[i].getAttribute("Postcode");
var Gemeente = markers[i].getAttribute("Gemeente");
var type = markers[i].getAttribute("type");
var point = new GLatLng(parseFloat(markers[i].getAttribute("Lat")),
parseFloat(markers[i].getAttribute("Lng")));
var marker = createMarker(point, Plaatsnaam, Straat, Nr, Postcode, Gemeente, type);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, Plaatsnaam, Straat, Nr, Postcode, Gemeente, type) {
var marker = new GMarker(point, customIcons[type]);
var html = Plaatsnaam + "<br/>" + Straat + " " + Nr + "<br />" + Postcode + " " + Gemeente;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
//<![CDATA[
var iconBlue = new GIcon();
iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);
var iconRed = new GIcon();
iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);
var customIcons = [];
customIcons["restaurant"] = iconBlue;
customIcons["bar"] = iconRed;
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
//map.addControl(new GSmallMapControl()); // inuitzoemen enkel met + -
map.addControl(new GLargeMapControl()); // in uit zoemen met + - en lijn er tussen
map.addControl(new GMapTypeControl());
// op het punt waar gecentreerd, hoogt en sateliet + kaard standaard
map.setCenter(new GLatLng(50.84064, 4.38354), 7, G_HYBRID_MAP);
GDownloadUrl("googlemaps/googlexml2.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var Plaatsnaam = markers[i].getAttribute("Plaatsnaam");
var Straat = markers[i].getAttribute("Straat");
var Nr = markers[i].getAttribute("Nr");
var Postcode = markers[i].getAttribute("Postcode");
var Gemeente = markers[i].getAttribute("Gemeente");
var type = markers[i].getAttribute("type");
var point = new GLatLng(parseFloat(markers[i].getAttribute("Lat")),
parseFloat(markers[i].getAttribute("Lng")));
var marker = createMarker(point, Plaatsnaam, Straat, Nr, Postcode, Gemeente, type);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, Plaatsnaam, Straat, Nr, Postcode, Gemeente, type) {
var marker = new GMarker(point, customIcons[type]);
var html = Plaatsnaam + "<br/>" + Straat + " " + Nr + "<br />" + Postcode + " " + Gemeente;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
XML:
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
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
<?php
require("googleDB.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM duiklocatie WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'Plaatsnaam="' . parseToXML($row['Plaatsnaam']) . '" ';
echo 'Straat="' . parseToXML($row['Straat']) . '" ';
echo 'Nr="' . parseToXML($row['Nr']) . '" ';
echo 'Postcode="' . parseToXML($row['Postcode']) . '" ';
echo 'Gemeente="' . parseToXML($row['Gemeente']) . '" ';
echo 'Lat="' . $row['Lat'] . '" ';
echo 'Lng="' . $row['Lng'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
require("googleDB.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM duiklocatie WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'Plaatsnaam="' . parseToXML($row['Plaatsnaam']) . '" ';
echo 'Straat="' . parseToXML($row['Straat']) . '" ';
echo 'Nr="' . parseToXML($row['Nr']) . '" ';
echo 'Postcode="' . parseToXML($row['Postcode']) . '" ';
echo 'Gemeente="' . parseToXML($row['Gemeente']) . '" ';
echo 'Lat="' . $row['Lat'] . '" ';
echo 'Lng="' . $row['Lng'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
Gewijzigd op 01/01/1970 01:00:00 door Philippe
map.addControl(new GSmallMapControl());
dan kunnen ze zelf zoomen...
't is echt de bedoeling van als ze op een plaats plaatsnaam klikken die ik heb opgegeven dat google maps zich inzoomt op die plaats