2012-05-23 45 views

回答

2

到目前爲止,我見過的最流暢的方法使用KML文件。 This is the original

我扯下了KML到最低限度:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
    <Document> 
     <ScreenOverlay> 
     <Icon> 
      <href>http://code.google.com/apis/kml/documentation/crosshairs.png</href> 
     </Icon> 
     <overlayXY x="0.5" y="0.5" xunits="fraction" yunits="fraction"/> 
     <screenXY x="0.5" y="0.5" xunits="fraction" yunits="fraction"/> 
     <rotationXY x="0.5" y="0.5" xunits="fraction" yunits="fraction"/> 
     <size x="0" y="0" xunits="pixels" yunits="pixels"/> 
     </ScreenOverlay> 
    </Document> 
</kml> 

在地圖代碼,所有你需要做的是設置與選項preserveViewport=true的KML層。請注意,如果您在本地進行測試,KML文件仍然需要上傳到公共場所。

var crosshairLayer = new google.maps.KmlLayer( 
     'http://freezoo.alwaysdata.net/justcrosshair2.kml', 
     {preserveViewport: true}); 

    crosshairLayer.setMap(map); 

的jsfiddle style 1 style 2

(他們兩個KML文件兩個不同的圖標。)

+0

將這項工作在移動應用中?我正在使用PhoneGap和jQuery Mobile。這方面的經驗? – New2This

+0

(也是風格2小提琴壞了,fyi) – New2This

+0

我有3個小時的經驗試圖讓Android世界上的模擬器:)在花費太多時間之前,請確保電話/模擬器可以加載[樣本KML(點擊這裏)](http://maps.google.com/maps?f=q&hl=en&q=http://kmlscribe.googlepages.com/SamplesInMaps.kml&ie=UTF8&ll=36.879621,-53.4375&spn=103.772916,208.476563&z=2&om= 1)就像一個普通的瀏覽器。請注意,樣本和樣式2中都很難看到十字準線,因爲它只能在海洋上看到。我所做的只是改變圖標圖像鏈接。它應該工作,也許只是需要很長時間才能加載。 –

相關問題