Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 由于css的原因,没有显示图像标记,仅显示最后一个标记_Javascript_Css_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 由于css的原因,没有显示图像标记,仅显示最后一个标记

Javascript 由于css的原因,没有显示图像标记,仅显示最后一个标记,javascript,css,google-maps,google-maps-api-3,Javascript,Css,Google Maps,Google Maps Api 3,我有一个谷歌地图,它在几周前还运行得很好 我的问题是,现在,所有标签标记都显示在正确的位置,但只显示最后一张图像 我在生成的html代码中看到,所有图像都在这里,但它们都有相同的位置(这就是为什么我只能看到最后一个) 我再说一遍:我敢肯定,它以前是有效的!也许谷歌改变了什么(我称之为脚本:) 这是我的密码: jQuery(function() { var stops = []; var nbPoints = $('#nbPoints').val(); for (var

我有一个谷歌地图,它在几周前还运行得很好

我的问题是,现在,所有标签标记都显示在正确的位置,但只显示最后一张图像

我在生成的html代码中看到,所有图像都在这里,但它们都有相同的位置(这就是为什么我只能看到最后一个)

我再说一遍:我敢肯定,它以前是有效的!也许谷歌改变了什么(我称之为脚本:)

这是我的密码:

 jQuery(function() {
    var stops = [];
    var nbPoints = $('#nbPoints').val();
    for (var i = 1; i <= nbPoints; i++) {
        if($('#latitude'+i).val() && $('#longitude'+i).val())
            stops.push({"Geometry":{"Latitude":$('#latitude'+i).val(),"Longitude":$('#longitude'+i).val()}});
    }

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

    // new up complex objects before passing them around
    var directionsDisplay = new window.google.maps.DirectionsRenderer({suppressMarkers: true});
    var directionsService = new window.google.maps.DirectionsService();

    Tour_startUp(stops);

    window.tour.loadMap(map, directionsDisplay);
    window.tour.fitBounds(map);

    if (stops.length > 1)
        window.tour.calcRoute(directionsService, directionsDisplay);
    else $("#message").html("Erreur : Aucune coordonnée renseignée!");

});

function Tour_startUp(stops) {
    if (!window.tour) window.tour = {
        updateStops: function (newStops) {
            stops = newStops;
        },
        // map: google map object
        // directionsDisplay: google directionsDisplay object (comes in empty)
        loadMap: function (map, directionsDisplay) {
            var myOptions = {
                zoom: 13,
                center: new window.google.maps.LatLng($('#latitudeInit').val(),$('#longitudeInit').val()), 
                mapTypeId: window.google.maps.MapTypeId.ROADMAP
            };
            map.setOptions(myOptions);
            directionsDisplay.setMap(map);
        },
        fitBounds: function (map) {
            var bounds = new window.google.maps.LatLngBounds();

            // extend bounds for each record
            jQuery.each(stops, function (key, val) {
                var myLatlng = new window.google.maps.LatLng(val.Geometry.Latitude, val.Geometry.Longitude);
                bounds.extend(myLatlng);
            });
            map.fitBounds(bounds);
        },
        calcRoute: function (directionsService, directionsDisplay) {
            var batches = [];
            var itemsPerBatch = 10; // google API max = 10 - 1 start, 1 stop, and 8 waypoints
            var itemsCounter = 0;
            var wayptsExist = stops.length > 0;

            while (wayptsExist) {
                var subBatch = [];
                var subitemsCounter = 0;

                for (var j = itemsCounter; j < stops.length; j++) {
                    subitemsCounter++;
                    subBatch.push({
                        location: new window.google.maps.LatLng(stops[j].Geometry.Latitude, stops[j].Geometry.Longitude),
                        stopover: true
                    });
                    if (subitemsCounter == itemsPerBatch)
                        break;
                }

                itemsCounter += subitemsCounter;
                batches.push(subBatch);
                wayptsExist = itemsCounter < stops.length;
                // If it runs again there are still points. Minus 1 before continuing to
                // start up with end of previous tour leg
                itemsCounter--;
            }

            // now we should have a 2 dimensional array with a list of a list of waypoints
            var combinedResults;
            var unsortedResults = [{}]; // to hold the counter and the results themselves as they come back, to later sort
            //var directionsResultsReturned = 0;
            var directionsResultsReturned = new Array();
            directionsResultsReturned[0]=0;

            for (var k = 0; k < batches.length; k++) {
                var lastIndex = batches[k].length - 1;
                var start = batches[k][0].location;
                var end = batches[k][lastIndex].location;

                // trim first and last entry from array
                var waypts = [];
                waypts = batches[k];
                waypts.splice(0, 1);
                waypts.splice(waypts.length - 1, 1);

                var request = {
                    origin: start,
                    destination: end,
                    waypoints: waypts,
                    travelMode: window.google.maps.TravelMode.DRIVING
                };

                creerRoute(k,request,batches,directionsService,unsortedResults,combinedResults,directionsResultsReturned,directionsDisplay);
            }
        }
    };
}

var infowindow = new google.maps.InfoWindow(
  { 
    size: new google.maps.Size(150,50)
  });

var icons = new Array();
icons["red"] = new google.maps.MarkerImage("mapIcons/marker_red.png",
      // This marker is 20 pixels wide by 34 pixels tall.
      new google.maps.Size(20, 34),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is at 9,34.
      new google.maps.Point(9, 34));


function getMarkerImage(numero, type, anomalie) {

    var url_img = "../img/";
    var type = new String(type);

    if(anomalie) url_img+="anomalie.png";
    else{
        switch(type.toUpperCase()){
            case "LAVAGE" : url_img+="shower.png"; break;
            case "EAU" : url_img+="waterdrop.png"; break;
            default : url_img+="stop.png"; break;
        }
    }

    icons[numero] = new google.maps.MarkerImage(url_img,
        new google.maps.Size(34, 34),
        new google.maps.Point(0,0),
        new google.maps.Point(9, 34));

    return icons[numero];

}
  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.

  var iconImage = new google.maps.MarkerImage('mapIcons/marker_red.png',
      // This marker is 20 pixels wide by 34 pixels tall.
      new google.maps.Size(34, 34),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is at 9,34.
      new google.maps.Point(9, 34));
  var iconShadow = new google.maps.MarkerImage('http://www.google.com/mapfiles/shadow50.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(37, 34),
      new google.maps.Point(0,0),
      new google.maps.Point(9, 34));
      // Shapes define the clickable region of the icon.
      // The type defines an HTML &lt;area&gt; element 'poly' which
      // traces out a polygon as a series of X,Y points. The final
      // coordinate closes the poly by connecting to the first
      // coordinate.
  var iconShape = {
      coord: [9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0],
      type: 'poly'
  };



function createMarker(map, latlng, label, html, numero, type, anomalie) {

    var contentString = '<b>'+label+'</b><br>'+html;

    var marker = new MarkerWithLabel({
        position: latlng,
        map: map,
        draggable: false,
        raiseOnDrag: true,
        icon : getMarkerImage(numero,type,anomalie),
        labelContent: numero,
        labelAnchor: new google.maps.Point(0, 0),
        labelClass: "labels",
        labelInBackground: false
      });
    marker.myname = label;

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString); 
        infowindow.open(map,marker);
    });

    return marker;
}


function creerRoute(kk,request,batches,directionsService,unsortedResults,combinedResults,directionsResultsReturned,directionsDisplay) {

    directionsService.route(request, function (result, status) {

        if (status == window.google.maps.DirectionsStatus.OK) {

            var unsortedResult = { order: kk, result: result };
            unsortedResults.push(unsortedResult);

            directionsResultsReturned[0]++;

            if (directionsResultsReturned[0] == batches.length) // we've received all the results. put to map
            {
                // sort the returned values into their correct order
                unsortedResults.sort(function (a, b) { return parseFloat(a.order) - parseFloat(b.order); });
                var count = 0;
                for (var key in unsortedResults) {
                    if (unsortedResults[key].result != null) {
                        if (unsortedResults.hasOwnProperty(key)) {
                            if (count == 0) // first results. new up the combinedResults object
                                combinedResults = unsortedResults[key].result;
                            else {
                                // only building up legs, overview_path, and bounds in my consolidated object. This is not a complete
                                // directionResults object, but enough to draw a path on the map, which is all I need
                                combinedResults.routes[0].legs = combinedResults.routes[0].legs.concat(unsortedResults[key].result.routes[0].legs);
                                combinedResults.routes[0].overview_path = combinedResults.routes[0].overview_path.concat(unsortedResults[key].result.routes[0].overview_path);

                                combinedResults.routes[0].bounds = combinedResults.routes[0].bounds.extend(unsortedResults[key].result.routes[0].bounds.getNorthEast());
                                combinedResults.routes[0].bounds = combinedResults.routes[0].bounds.extend(unsortedResults[key].result.routes[0].bounds.getSouthWest());
                            }
                            count++;
                        }
                    }
                }
                directionsDisplay.setDirections(combinedResults);
                var legs = combinedResults.routes[0].legs;

                for (var i=0; i < legs.length;i++){
                    var j = i + 1;
                    var markerletter = $('#ordre'+j).val();
                    var anomalie=false;
                    var html = $('#infospoint'+j).val();
                    if($('#infoschocspoint'+j).length){
                        anomalie = true;
                        html+="<br/>"+$('#infoschocspoint'+j).val();
                    }
                    createMarker(directionsDisplay.getMap(),legs[i].start_location,$('#titrepoint'+j).val(),html,markerletter,$('#type'+j).val(),anomalie);
                }
                var i=legs.length + 1;
                var markerletter = $('#ordre'+i).val();
                var anomalie=false;
                var html = $('#infospoint'+i).val();
                if($('#infoschocspoint'+i).length){
                    anomalie = true;
                    html+="<br/>"+$('#infoschocspoint'+i).val();
                }
                createMarker(directionsDisplay.getMap(),legs[legs.length-1].end_location,$('#titrepoint'+i).val(),html,markerletter,$('#type'+i).val(),anomalie);
            }
        }else {
            if (status == window.google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
                setTimeout( function(){
                    creerRoute(kk,request,batches,directionsService,unsortedResults,combinedResults,directionsResultsReturned,directionsDisplay); 
                }, 200);

            }else{
                $("#message").html("Erreur : Code "+status);
            }   
          }
    });
}
jQuery(函数(){
var停止=[];
var nbPoints=$('#nbPoints').val();
对于(变量i=1;i 1)
window.tour.calcRoute(directionsService,directionsDisplay);
else$(“#message”).html(“Erreur:Aucune coordonnée renseignée!”);
});
功能巡更器启动(停止){
如果(!window.tour)window.tour={
updateStops:函数(newStops){
站点=新闻头条;
},
//地图:谷歌地图对象
//directionsDisplay:google directionsDisplay对象(为空)
loadMap:功能(地图、方向显示){
变量myOptions={
缩放:13,
中心:newwindow.google.maps.LatLng($('latitudeInit').val(),$('latitudeInit').val()),
mapTypeId:window.google.maps.mapTypeId.ROADMAP
};
map.setOptions(myOptions);
方向显示.setMap(地图);
},
fitBounds:函数(映射){
var bounds=new window.google.maps.LatLngBounds();
//扩展每个记录的边界
jQuery.each(停止,函数(键,val){
var myLatlng=new window.google.maps.LatLng(val.Geometry.lation,val.Geometry.Longitude);
扩展(myLatlng);
});
映射边界(bounds);
},
calcRoute:函数(方向服务、方向显示){
var批次=[];
var itemsPerBatch=10;//google API max=10-1个起点、1个终点和8个航路点
var ItemsCenter=0;
var wayptsExist=停止。长度>0;
while(性别歧视者){
var子批次=[];
var SubItemsCenter=0;
对于(var j=ItemsCenter;j<script  type="text/javascript"  src="http://maps.google.com/maps/api/js?sensor=false&v=3.3"></script>