Маркер карт Google не показывает JavaScript

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

Мой загрузчик карт идеален, но мои оценки не появятся.

Я не совсем понимаю, почему это происходит?

редактировать 1:

Вот вся функция, надеюсь, она поможет ответить на некоторые ваши вопросы:

 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);
});
});
});
}

Редактировать 2

вот мой xml код, он отлично работает! это просто мой маркер на карте, который не работает

<?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>';

?>

1

Решение

В вашем XML:

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

В вашем JS:

markerElem.getAttribute('latitude')

Ты используешь lat а также latitude, lng а также longitude, name а также username, Поэтому убедитесь, что вы используете правильные атрибуты!


Вы можете легко отладить свой код, используя эту простую строку в вашем JS:

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

И следите за своей консолью JavaScript (в приличном браузере, таком как Chrome или Firefox). Если вы не знаете, где это, пожалуйста, проверьте документацию вашего браузера.

1

Другие решения

Проверьте, находится ли «карта» в области видимости.

Кроме того, сохраните этот код в простое событие карты:

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

Попробуй это:

Позвони своему див

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

В сценарии:

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

Поместите свойства маркера и значок, попробуйте с помощью 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'>\n\<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);
});

})
-1
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector