2015-04-08 26 views
-1

我有一個網站,我加載和使用kmz文件。我的問題是,GEO的位置不工作,我的意思是它的工作,但它不顯示街道因爲JavaScript加載kmz文件,並把重點放在KMZ地圖上,而不是你的GEOlocation。Gmaps搜索和kmz加載javascript

總之,這裏是代碼,所以你可以看看什麼是錯的:

<script type="text/javascript"> 
    var map, infoWindow; 
    $(document).ready(function(){ 
     infoWindow = new google.maps.InfoWindow({}); 
     map = new GMaps({ 
     el: '#map', 
     zoom: 20, 
     lat: 46.044414, 
     lng: 14.508105, 
     }); 
     map.loadFromKML({ 
     url: 'http://blabla.com/blabla.kmz', 
     url: 'http://blabla.com/blabla2.kmz', 
     suppressInfoWindows: true, 
     events: { 
      click: function(point){ 
      infoWindow.setContent(point.featureData.infoWindowHtml); 
      infoWindow.setPosition(point.latLng); 
      infoWindow.open(map.map); 
      } 
     } 
     }); 
    }); 
    </script> 
<script type="text/javascript"> 
GMaps.geolocate({ 
    success: function(position) { 
    map.setCenter(position.coords.latitude, position.coords.longitude); 
    }, 
    error: function(error) { 
    alert('Geolocation failed: '+error.message); 
    }, 
    not_supported: function() { 
    alert("Your browser does not support geolocation"); 
    }, 
    always: function() { 
    alert("Success!"); 
    } 
}); 
</script> 

哦,我差點忘了,我使用Gmaps.js

回答

0

GMaps documentation

而且,loadFromKML接受google.maps.KmlLayerOptions中定義的任何選項。

使用{preserveViewport: true}選項。

preserveViewport,用於布爾默認情況下,輸入地圖會居中和縮放到的層中的內容的邊界框。如果此選項設置爲true,則視口保持不變,除非地圖的中心和縮放從未設置。

map.loadFromKML({ 
    url: 'http://blabla.com/blabla.kmz', 
    url: 'http://blabla.com/blabla2.kmz', 
    preserveViewport: true, 
    suppressInfoWindows: true, 
    events: { 
     click: function(point){ 
     infoWindow.setContent(point.featureData.infoWindowHtml); 
     infoWindow.setPosition(point.latLng); 
     infoWindow.open(map.map); 
     } 
    } 
+0

非常感謝您先生:D您保存了一天:) – gasperko