2012-10-25 94 views
-2

我們使用的是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(); 
}); 

不幸的是,地圖上會並不在這一點上渲染。必須做些什麼來修改上述代碼才能呈現正確的地圖和位置?

+0

你是什麼意思「這不是正確的地址」?如果我在[我的瀏覽器]中輸入[URL](https://maps.google.com/maps?saddr=Howell+Sand+Co+INC++2300+East+Hastings+Avenue+Amarillo,+TX+79108,+美國+(806)+ 383-1721&hl = en&ll = 35.250175,-101.804552&spn = 0.056074,0.076218&sll = 37.0625,-95.677068&sspn = 49.624204,79.013672&mra = ls&t = m&z = 14&iwloc = ddw0)對我來說是正確的(儘管我沒有去過德克薩斯州的阿馬裏洛,所以我不能肯定地說)。 – geocodezip

+0

對不起,應該已經更清楚了。地圖呈現,但不會正確繪製地址。也就是說,地圖以完全不同的狀態繪製地址。 – SidC

+0

什麼地址在什麼狀態下繪圖? – geocodezip

回答

1

that page上的地圖與您發佈的代碼無關。它是Google Maps API v2地圖(即使它要求v1)。下面的代碼。該標記正是代碼在Latitude =「37.0625」,Longitude =「-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> 
+0

感謝您的支持。在上面的代碼修復中,我應該刪除myLatitude和myLongitude語句嗎?如何將它連接到我的地圖div中進行渲染? – SidC

+0

假設您想要[2300 Hastings Ave,Amarillo,TX]的標記(http://www.geocodezip.com/v3_example_geo2.asp?addr1=2300+East+Hastings+Avenue+Amarillo,+TX+79108&geocode=1&zoom= 17&type = m),你可能想把它們設置爲35.249369,-101.807561 – geocodezip

+0

在你的地圖上,我應該把getElementById設置爲'map',因爲我想用class = map在div中嵌入地圖? – SidC

0

URL中有無關的空白。去掉它。

<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> 
+0

謝謝。發佈代碼時,這是我的編輯錯誤。 – SidC