Google地图无法呈现正确的位置

时间:2012-10-25 18:08:22

标签: google-maps dotnetnuke

我们在DotNetNuke 6.0皮肤中使用以下代码:

<iframe width="310" height="226" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="http://maps.google.com/maps?  f=d&amp;source=s_d&amp;saddr=Howell+Sand+Co+INC++2300+East+Hastings+Avenue+Amarillo,+TX+79108,+United+State+of+America+(806)+383-1721&amp;daddr=&amp;hl=en&amp;geocode=&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=49.624204,79.013672&amp;mra=ls&amp;ie=UTF8&amp;ll=37.0625,-95.677068&amp;spn=49.624204,79.013672&amp;t=m&amp;iwloc=ddw0&amp;output=embed">
</iframe>
<br />
<small><a href="http://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Howell+Sand+Co+INC++2300+East+Hastings+Avenue+Amarillo,+TX+79108,+United+State+of+America+(806)+383-1721&amp;daddr=&amp;hl=en&amp;geocode=&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=49.624204,79.013672&amp;mra=ls&amp;ie=UTF8&amp;ll=37.0625,-95.677068&amp;spn=49.624204,79.013672&amp;t=m&amp;iwloc=ddw0"
style="color: #0000FF; text-align: left">View Larger Map</a></small>

在其当前状态下,将在页面上呈现地图。但是,它呈现的位置不是正确的地址。请参阅当前行为here

我已经在静态地图API上进一步阅读了,我想知道是否应重新编写以上内容来调用该API?或者,我们应采取不同的方法吗?

更新: 我重写了以下javascript:

function initialize() {

var mapOptions = {
    center: new google.maps.LatLng(35.249369, -101.807561)
};
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
GEvent.addListener(marker, "mouseover ", function() {
    marker.openInfoWindowHtml(" < html > < body style = \"font-size: 8px;\"><table><tr><td align='left'><b>Company:</b> </td><td>Howell Sand Co Inc.<br/></td></tr>" + "<tr><td style=\"vertical-align:top;\"><b>Address:</b> </td><td>2300 East Hastings Avenue,<br/> Amarillo, TX 79108 (806) 383-1721 </td>" + "</tr></body></html>");
});
map.addOverlay(marker);
}

$(document).ready(function() {
initialize();
}); 

不幸的是,此时地图根本无法渲染。修改上面的代码以呈现正确的地图和位置必须做些什么?

2 个答案:

答案 0 :(得分:1)

that page上的地图与您发布的代码无关。它是Google Maps API v2地图(即使它需要v1)。代码如下。该标记正是代码将其置于纬度=“37.0625”,经度=“ - 95.677068”,即somewhere in Kansas的位置。请注意,v2 API已弃用,可能最早在2013年5月停止工作。

 <script src="http://maps.google.com/maps?file=api&v=1&key=AIzaSyCsOdhbicIzYAIw7446dYmhHBGjmpZiS48"
    type="text/javascript"></script>
<script type="text/javascript">
    function initialize() {

        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById('map_canvas'));
            map.setCenter(new GLatLng(37.4419, -122.1419), 12);

            map.setUIToDefault();

            var baseIcon = new GIcon(G_DEFAULT_ICON);
            baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
            baseIcon.iconSize = new GSize(20, 34);
            baseIcon.shadowSize = new GSize(37, 34);
            baseIcon.iconAnchor = new GPoint(9, 34);
            baseIcon.infoWindowAnchor = new GPoint(9, 2);


            var myLatitude = "37.0625";
            var myLongitude = "-95.677068";
            var strStorename = "Howell Sand Co Inc";
            var strAddress1 = "2300 East Hastings Avenue, Amarillo, TX 79108 (806) 383-1721";
            var strURL = document.getElementById('dnn_hdfStoreURL').value;


            var URL = "";
            if (strURL != "") {
                URL = "<tr><td><b>URL:</b></td><td><a href=\"" + strURL + "\">" + strURL + " </a></td></tr>";
            }
            var point = new GLatLng(myLatitude, myLongitude);

            map.setCenter(point, 12);


            var letteredIcon = new GIcon(baseIcon);
            letteredIcon.image = "images/howellsandpointer.png";

            // Set up our GMarkerOptions object
            markerOptions = { icon: letteredIcon };
            var marker = new GMarker(point, markerOptions);

            GEvent.addListener(marker, "mouseover", function() {
                marker.openInfoWindowHtml(
                                           "<html><body style=\"font-size: 8px;\"><table><tr><td align='left'><b>Company:</b> </td><td>Howell Sand Co Inc.<br/></td></tr>" +
                                                    "<tr><td style=\"vertical-align:top;\"><b>Address:</b> </td><td>2300 East Hastings Avenue,<br/> Amarillo, TX 79108 (806) 383-1721 </td>" +
                                                    "</tr></body></html>");
            });
            map.addOverlay(marker);
        }

    }

    $(document).ready(function() {
        initialize();
    }); 
</script>

答案 1 :(得分:0)

网址中有无关的空格。删除它。

<iframe width="310" height="226" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="http://maps.google.com/maps?  f=d&amp;source=s_d&amp;saddr=Howell+Sand+Co+INC++2300+East+Hastings+Avenue+Amarillo,+TX+79108,+United+State+of+America+(806)+383-1721&amp;daddr=&amp;hl=en&amp;geocode=&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=49.624204,79.013672&amp;mra=ls&amp;ie=UTF8&amp;ll=37.0625,-95.677068&amp;spn=49.624204,79.013672&amp;t=m&amp;iwloc=ddw0&amp;output=embed">
</iframe>


<iframe width="310" height="226" frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="http://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Howell+Sand+Co+INC++2300+East+Hastings+Avenue+Amarillo,+TX+79108,+United+State+of+America+(806)+383-1721&amp;daddr=&amp;hl=en&amp;geocode=&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=49.624204,79.013672&amp;mra=ls&amp;ie=UTF8&amp;ll=37.0625,-95.677068&amp;spn=49.624204,79.013672&amp;t=m&amp;iwloc=ddw0&amp;output=embed">
</iframe>