Jump to content
  • Advertisement
Sign in to follow this  
Pedro Alves

google map don´t work

Recommended Posts

i can´t put work my map load the correctly with data it is in my data base

what i doing wrong

index.php

 <?php
 foreach ($servicos->getnomeempresa($m['Nome'])as $emp1):
     
 $dom = new DOMDocument("1.0");
 
 
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
$node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $emp1['Nome']);
  $newnode->setAttribute("address", $emp1['morada']);
  $newnode->setAttribute("lat", $emp1['lat']);
  $newnode->setAttribute("lng", $emp1['lng']);
  $newnode->setAttribute("type",$emp1['type']);
  echo $dom->saveXML();
endforeach;

//$xmlfile = $doc->dump_mem();

?>

index.php

<script>
 
 var customLabel = {
        restaurant: {
          label: 'R'
        },
        bar: {
          label: 'B'
        }
      };
        function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: new google.maps.LatLng(-33.863276, 151.207977),
          zoom: 12
        });
        var infoWindow = new google.maps.InfoWindow;

          // Change this depending on the name of your PHP or XML file
          downloadUrl('', function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName('marker');
            Array.prototype.forEach.call(markers, function(markerElem) {
              var name = markerElem.getAttribute('name');
              var address = markerElem.getAttribute('address');
              var type = markerElem.getAttribute('type');
              var point = new google.maps.LatLng(
                  parseFloat(markerElem.getAttribute('lat')),
                  parseFloat(markerElem.getAttribute('lng')));

              var infowincontent = document.createElement('div');
              var strong = document.createElement('strong');
              strong.textContent = name
              infowincontent.appendChild(strong);
              infowincontent.appendChild(document.createElement('br'));

              var text = document.createElement('text');
              text.textContent = address
              infowincontent.appendChild(text);
              var icon = customLabel[type] || {};
              var marker = new google.maps.Marker({
                map: map,
                position: point,
                label: icon.label
              });
              marker.addListener('click', function() {
                infoWindow.setContent(infowincontent);
                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>

 

Edited by Landi20

Share this post


Link to post
Share on other sites
Advertisement

how i put this

 downloadUrl('', function(data) {

to load a php file

i have try put like this

downloadUrl('map.php?Nome=<?php echo $m;?>', function(data) {

and not work

Edited by Landi20

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!