Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html >
- <head>
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
- <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
- <title>Google Maps</title>
- <script src="https://maps.googleapis.com/maps/api/js?key=my key"
- type="text/javascript"></script>
- <script type="text/javascript">
- var customIcons = {
- restaurant: {
- icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
- },
- bar: {
- icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
- }
- };
- function load() {
- var map = new google.maps.Map(document.getElementById("map"), {
- center: new google.maps.LatLng(52.3702160, 4.8951680),
- zoom: 13,
- mapTypeId: 'roadmap'
- });
- var infoWindow = new google.maps.InfoWindow;
- downloadUrl("createxml.php", function(data) {
- var xml = data.responseXML;
- var markers = xml.documentElement.getElementsByTagName("marker"); //this line contains error
- for (var i = 0; i < markers.length; i++) {
- var name = markers[i].getAttribute("name");
- var address = markers[i].getAttribute("address");
- var type = markers[i].getAttribute("type");
- var point = new google.maps.LatLng(
- parseFloat(markers[i].getAttribute("lat")),
- parseFloat(markers[i].getAttribute("lng")));
- var html = "<b>" + name + "</b> <br/>" + address;
- var icon = customIcons[type] || {};
- var marker = new google.maps.Marker({
- map: map,
- position: point,
- icon: icon.icon
- });
- bindInfoWindow(marker, map, infoWindow, html);
- }
- });
- }
- function bindInfoWindow(marker, map, infoWindow, html) {
- google.maps.event.addListener(marker, 'click', function() {
- infoWindow.setContent(html);
- infoWindow.open(map, marker);
- });
- }
- function downloadUrl(url, callback) {
- var request = window.ActiveXObject ?
- new ActiveXObject('Microsoft.XMLHTTP') :
- new XMLHttpRequest;
- request.onreadystatechange = function() {
- if (request.readyState == 4) {
- request.onreadystatechange = doNothing;
- callback(request, request.status);
- }
- };
- request.open('GET', url, true);
- request.send(null);
- }
- function doNothing() {}
- </script>
- </head>
- <body onload="load()">
- <div id="map" style="width: 500px; height: 300px"></div>
- </body>
- </html>
- <?xml version="1.0" encoding="UTF-8"?>
- <markers>
- <marker type="bar" lng="4.892607" lat="52.371613" address="oudezijds" name="barretje"/>
- </markers>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement