Jorge
Jorge

Reputation: 18237

markers doesn't show

i have this method in my code that load the markers but it doesn't work.

function loadMarkers() {

if (locations.length > 0) {
    var local = locations.split(';');
    for (var i = 0; i < local.length; i++) {
        var center = local[i].split(',');
        var iconoMarca = imagePath;
        var position = new google.maps.LatLng(center[0],
                                        center[1]);
        var marker = new google.maps.Marker({
            position: position,
            image: iconoMarca,
            optimized: false,
            map: map,
            draggable: true
        });
    }
}
}

i know that the method it's called because i make a debug with chrome but can't see where the problem, for me the code it's fine. This is the listener of the event

google.maps.event.addListenerOnce(map, 'idle', loadMarkers);

thi is the function that initialize the map

function initialize() {

$(".btnSaveMarkers").click(saveMarkers);
$(".btnResetMap").click(resetMap);
$(".btnCleanMarkers").click(removeAllMarkers);

//build the map
$.ajax({
    async: false,
    type: "POST",
    url: "SetMarkers.aspx/findMapParameters",
    data: "{idMapa: '" + idMap + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",   
    success: response
});

var mapDiv = document.getElementById('map-canvas');
map = new google.maps.Map(mapDiv, {
    center: new google.maps.LatLng(lat, lng),
    zoom: zoom,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    disableDefaultUI: true,
    disableDoubleClickZoom: true
});

google.maps.event.addListenerOnce(map, 'idle', loadMarkers);

google.maps.event.addListener(map, 'dblclick', addMarkers);
}

Upvotes: 2

Views: 199

Answers (1)

Jorge
Jorge

Reputation: 18237

mi problem was simple i'm receiving the center wrong, that only thing that i need to do was swtich the lat by lng center[1] by center[0] and also add the zoom associated to the marker with the property zoom

Upvotes: 2

Related Questions