简体   繁体   English

jQuery没有显示Google Maps

[英]jQuery is not showing Google Maps

I am going to describe my problem as good as I can. 我将尽我所能描述我的问题。 If you go to http://91.123.196.34/Dentalo.Portal/ and click on the one location icon that is located in Sweden. 如果您转到http://91.123.196.34/Dentalo.Portal/并单击位于瑞典的一个位置图标。 You will get this image 你会得到这张图片

在此处输入图片说明

If you click on Information button and then tab menu "Vägbeskrivning" you will get this image. 如果单击“信息”按钮,然后单击选项卡菜单“Vägbeskrivning”,则将获得此图像。

在此处输入图片说明

Goole maps is rendering as I want it to. Goole地图正在按我的意愿进行渲染。 But if you close the popup and click the same information button again then Google maps is rendering as I want it to like this. 但是,如果您关闭弹出窗口,然后再次单击相同的信息按钮,则Google地图将按照我希望的方式进行渲染。

在此处输入图片说明

This is is giving me a headache, because I don't know how to solve this. 这让我头疼,因为我不知道该如何解决。

This is the html code that I have. 这是我拥有的html代码。

<div id="content_v4" class="tabscontent">

<!-- Start Google Map -->
<div id="map_canvas"></div>

<div class="one-page column bottom-3" id="textdirections">

    <div class="info-box top-3" id="direction-steps">
    </div>        
</div>

<div id="directions-panel"></div>
<!-- End -->

</div>  

and the jquery code 和jQuery代码

function showPopUp(id) {
//            window.jQuery("#tab_v4").click();
//            window.jQuery("#tab_v1").click();
//            window.jQuery("#tab_v4").click();
            window.jQuery( "#priceName" ).empty();
            window.jQuery( "#companyPrice" ).empty();
            window.jQuery( "#referencePrice" ).empty();
            window.jQuery( "#directions-panel" ).empty();
            window.jQuery("#dialog").dialog();
            window.jQuery(".ui-dialog").css("width", "+=350");
            //begin rest call
            var window.jQuerycompanyPrice = window.jQuery("#companyPrice");
            var window.jQueryreferencePrice = window.jQuery("#referencePrice");
            var window.jQuerypriceName = window.jQuery("#priceName");
            window.jQuery( "#content_v1" ).empty();
            var window.jQuerycontent_v1 = window.jQuery("#content_v1");
            //window.jQuery("#map_canvas").css("width", "500");
            //window.jQuery( "#tab_v1" ).addClass("active");
            window.jQuery.ajax({
                type: "GET",
                cache: false,
                async: false,
                url: "http://localhost/Dentalo.Rest.Service/Dentalo.svc/GetPrices/Company/" + id,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    window.jQuery.each(data, function (index, item) {
                        window.jQuerypriceName.append("<li>" + item.PriceType.Name + "</li>");
                        window.jQuerycompanyPrice.append("<li>" + item.RegularPrice + " kr</li>");
                        window.jQueryreferencePrice.append("<li>" + item.PriceType.ReferencePrice + " kr</li>");
                    });
                },
                error: function (msg, url, line) {
                    //alert('error trapped in error: function(msg, url, line)');
                    alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
                }
            });
            window.jQuery.ajax({
                type: "GET",
                cache: false,
                async: false,
                url: "http://localhost/Dentalo.Rest.Service/Dentalo.svc/Company/" + id,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    calculateRoute(window.jQuery("#latitude").val() + "," + window.jQuery("#longitude").val(), data.Address + ", " + data.State.County.Name);
                    window.jQuerycontent_v1.append("<h4>" + data.Name + "</h4>" +
                                       "<h4>Öppettider</h4><br />" +
                                       "<i class='icon-time s-20 color'></i> <br />" + data.OpeningHours.replace(/\r\n|\n|\r/g, '<br />') +
                                       "<br /><br /><h4>Hemsida</h4> <a href='" + data.Url + "'>" + data.Url + "</a><br />");
                    window.jQuery.each(data, function (index, item) {
                        window.jQuerypriceName.append("<li>" + item.PriceType.Name + "</li>");
                        window.jQuerycompanyPrice.append("<li>" + item.RegularPrice + " kr</li>");
                        window.jQueryreferencePrice.append("<li>" + item.PriceType.ReferencePrice + " kr</li>");
                    });
                },
                error: function (msg, url, line) {
                    //alert('error trapped in error: function(msg, url, line)');
                    alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
                }
            });
        }
        function calculateRoute(from, to) {
            // Center initialized to Naples, Italy
//            var myOptions = {
//                zoom: 10,
//                center: new google.maps.LatLng(40.84, 14.25),
//                mapTypeId: google.maps.MapTypeId.ROADMAP
//            };
            // Draw the map
            var mapObject = new google.maps.Map(document.getElementById("map_canvas"));
            var directionsService = new google.maps.DirectionsService();
            var directionsRequest = {
                origin: from,
                destination: to,
                travelMode: google.maps.DirectionsTravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC
            };
//              directionsDisplay = new google.maps.DirectionsRenderer();
//              directionsDisplay.setMap(map);
//              directionsDisplay.setPanel(document.getElementById('directions-panel'));

            directionsService.route(
                directionsRequest,
                function (response, status) {
                    if (status == google.maps.DirectionsStatus.OK) {

                        // Start/Finish icons
                        var icons = {
                            start: new google.maps.MarkerImage(
                            // URL
                            'http://a01c00487.ad.sogeti.se/dentalo.portal/assets/images/img/ui/imagefiles-location_map_pin_home_green.png',
                            // (width,height)
                            new google.maps.Size(64, 64),
                            // The origin point (x,y)
                            new google.maps.Point(0, 0),
                            // The anchor point (x,y)
                            new google.maps.Point(22, 32)
                            ),
                            end: new google.maps.MarkerImage(
                            // URL
                            'http://a01c00487.ad.sogeti.se/dentalo.portal/assets/images/img/ui/marker_location_blue.png',
                            // (width,height)
                            new google.maps.Size(46, 50),
                            // The origin point (x,y)
                            new google.maps.Point(0, 0),
                            // The anchor point (x,y)
                            new google.maps.Point(21, 53)
                            )
                        };

                        var directionsDisplay = new google.maps.DirectionsRenderer({
                            map: mapObject,
                            directions: response,
                            suppressMarkers: true
                        });
                        var leg = response.routes[0].legs[0];
                      directionsDisplay.setMap(mapObject);
                        var d = response.routes[0].legs[0];
                        if (d != null) {
                            var h = "";
                            for (var c = 0, g; g = d.steps[c]; ++c) {
                                var b = "";
                                if (g.transit != null) {
                                    b = ", <strong>avstigning:</strong> " + g.transit.arrival_stop.name;
                                }
                                h += "<div class='twelve columns bottom-1 float-left'>" + g.instructions + b + "</div><div class='four columns bottom-1 float-right'><strong>" + g.distance.text + ", " + g.duration.text + "</strong></div>";
                            }
                            //alert(h);
                            window.jQuery("#direction-steps").html(h);
                            window.jQuery("#textdirections").show();
                        }
                      directionsDisplay.suppressMarkers = true;
                      //directionsDisplay.setPanel(document.getElementById('directions-panel'));
                        makeMarker(leg.start_location, mapObject, icons.start, "title");
                        makeMarker(leg.end_location, mapObject, icons.end, 'title');
                    } 
                    else
                    {
                        window.jQuery("#error").append("Unable to retrieve your route<br />");
                    }
                }
            );
        }
        function makeMarker(position, map, icon, title) {
            new google.maps.Marker({
                position: position,
                map: map,
                icon: icon,
                title: title
            });
        }

Hope you understand. 希望你能理解。 I know its a messy description. 我知道它的描述很乱。 If it is a bad description delete. 如果描述不正确,请删除。 I have tried the best I can. 我已经尽力了。

Your problem is the somehow crippled map at startup? 您的问题是启动时以某种方式残缺的地图? This is very common with google maps on hidden elements. 这对于带有隐藏元素的Google地图非常普遍。 You must force it being redrawn by calling 您必须通过致电强制重绘

google.maps.event.trigger(mapObject, 'resize');

Looks like you are using something called "tytabs", which not seems to have events for showing / hiding the tabs. 似乎您使用的是“ tytabs”,似乎没有显示/隐藏标签的事件。

So I suggest you add this event to function calculateRoute , assuming tab_v4 is the id of the google map tab (Vägbeskrivning) : 因此,我建议您将此事件添加到function calculateRoute ,假设tab_v4是google map标签的id (Vägbeskrivning):

$("#tab_v4").click(function() {
   google.maps.event.trigger(mapObject, 'resize');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM