Google地图标记不显示JavaScript

var marker = new google.maps.Marker({
    map: map,
    position: point,
    icon: 'pointer.png',
    title: "test"
});

My map loader perfect, but my marks will not appear.

I do not quite understand why it is happening?

edit 1:

Here is the whole function, I hope it will help answer some of your questions:

 function initMap() {
     map = new google.maps.Map(document.getElementById('map'), {
         zoom: 16,
         center: new google.maps.LatLng(<?php echo $userRow['latitude']; ?>, <?php echo $userRow['longitude']; ?>),
     });
     var infoWindow = new google.maps.InfoWindow;

     // Change this depending on the name of your PHP or XML file
     downloadUrl('http://xxx.esy.es/test/test-marker.php', function(data) {
         var xml = data.responseXML;
         var markers = xml.documentElement.getElementsByTagName('marker');
         Array.prototype.forEach.call(markers, function(markerElem) {
             var name = markerElem.getAttribute('username');
             var address = markerElem.getAttribute('address');
             var point = new google.maps.LatLng(
                 parseFloat(markerElem.getAttribute('latitude')),
                 parseFloat(markerElem.getAttribute('longitude')));

             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 marker = new google.maps.Marker({
                 map: map,
                 position: point,
                 icon: 'pointer.png',
                 title: "test"
             });
             marker.addListener('click', function() {
                 infoWindow.setContent(infowincontent);
                 infoWindow.open(map, marker);
             });
         });
     });
 }

Edit 2

here it my xml code, it works fine! it is just my marker on the map that do not work

<?php
include_once 'test-dbconnect.php';
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}


header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

 $sql = "select * from tbl_users";
    $result = mysqli_query($DBcon, $sql) or die("Error in Selecting " . mysqli_error($DBcon));

    //create an array
    $emparray = array();
    while($row =mysqli_fetch_assoc($result))
    {
        $emparray[] = $row;

  echo '<marker ';
  echo 'name="' . parseToXML($row['username']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['latitude'] . '" ';
  echo 'lng="' . $row['longitude'] . '" ';
  echo '/>';
}


    //close the db connection
    mysqli_close($DBcon);

// End XML file
echo '</markers>';

?>

In your XML:

<marker name="test" address="sømærket 3 hørsholm" lat="55.880875" lng="12.448797"/>

In your JS:

markerElem.getAttribute('latitude')

You are using lat and latitude, lng and longitude, name and username. So make sure you use the right attributes!


You could easily debug your code by using this simple line in you JS:

console.log(markerElem.getAttribute('latitude'));

And watch your javascript console (in a decent browser like Chrome or Firefox). If you don't know where it is, please check your browser documentation.

Try this:

Call your div

<div id="map_canvas" style="height: 520px; border: 1; border-color: #000;" class="centered"></
<!-- This is the div that will contain the Google Map -->

In a Script:

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

And put your marker properties and icon, try it with JSON:

 $.each(data, function (i, item) {
            var marker = new google.maps.Marker({
                'position': new google.maps.LatLng(item.GeoLong, item.GeoLat),
                'map': map,
                'title': item.PlaceName
            });

            // Set Icon

            marker.setIcon('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png')

            // put in some information about each json object - in this case, the opening hours.
            var infowindow = new google.maps.InfoWindow({
                content: "<div class='infoDiv'>
\<h2 class='text-center'>" + item.PlaceName + "</h2></div></div>"
            });

            // finally hook up an "OnClick" listener to the map so it pops up out info-window when the marker-pin is clicked!
            google.maps.event.addListener(marker, 'click', function () {
                infowindow.open(map, marker);
            });

        })

Check if 'map' is in scope.

Also, keep this code code in map's idle event:

var marker = null;
google.maps.event.addListener(map, 'idle', function() {


   marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: 'pointer.png',
        title: "test"
   });
});